Call vba from bash


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Call vba from bash
# 15  
Old 10-27-2015
You are correct in that a message box displays when the workbook is opened. The VB is below with the hard-coded path in bold. Can the bash go to the excel file? The user can then run the VB and the output is stored as a text file. Thank you very much Smilie.

VB
Code:
 Private Sub Workbook_Open()
Dim sR As String
Dim sFile As String
    Sheets("Sheet1").Activate
    Range("A1").Select
    sR = MsgBox("Clear the sheet for new data?", vbQuestion + vbYesNo + vbDefaultButton2)
    If sR = vbYes Then
        Application.ScreenUpdating = False
        On Error Resume Next
        Application.DisplayAlerts = False
        Sheets("Sheet1").UsedRange.Clear
        ChDrive "N:\path\to\folder"
          ChDir "N:\path\to\folder"
         On Error GoTo ErrHandler:    ' cause an error
        sFile = Application.GetOpenFilename _
            (FileFilter:="Excel Workbooks, *.xlsx", MultiSelect:=False)
        Workbooks.OpenText Filename:=sFile, Origin:=437, StartRow:=1, DataType:=xlDelimited, _
            TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
            FieldInfo:=Array(Array(1, 1), Array(2, 1), _
            Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), Array(9, 1), _
            Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1), Array(14, 1), Array(15, 1), Array( _
            16, 1), Array(17, 1), Array(18, 1), Array(19, 1), Array(20, 1), Array(21, 1), Array(22, 1), _
            Array(23, 1), Array(24, 1), Array(25, 1), Array(26, 1), Array(27, 1), Array(28, 1), Array( _
            29, 1), Array(30, 1), Array(31, 1), Array(32, 1), Array(33, 1), Array(34, 1), Array(35, 1), _
            Array(36, 1), Array(37, 1), Array(38, 1), Array(39, 1), Array(40, 1), Array(41, 1), Array( _
            42, 1), Array(43, 1), Array(44, 1), Array(45, 1), Array(46, 1), Array(47, 1), Array(48, 1), _
            Array(49, 1), Array(50, 1), Array(51, 1), Array(52, 1), Array(53, 1), Array(54, 1), Array( _
            55, 1)), TrailingMinusNumbers:=True
        ActiveWorkbook.Sheets(1).UsedRange.Copy
        ThisWorkbook.Sheets("Sheet1").Range("A1").PasteSpecial
        Application.CutCopyMode = False
        ActiveWorkbook.Close False
        Sheets("Sheet1").Activate
        ActiveSheet.Range("A1").Select
        Application.ScreenUpdating = True
    End If
Exit Sub
ErrHandler:
    ' error handling code
       Application.Quit
    Resume Next
    
End Sub

This User Gave Thanks to cmccabe For This Post:
# 16  
Old 10-27-2015
You will need cmd.exe probably, to follow Windows file associations, but this can still be done from BASH. Something like cmd /C "start c:\\path\\to\\excel.xmlx" perhaps.
This User Gave Thanks to Corona688 For This Post:
# 17  
Old 10-27-2015
Thank you very much I will give that a try Smilie.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Using BATCH to call a BASH script on CygWin

I am trying to use a batch file to automatically execute a bash script with no luck this far. The batch script looks like this: C:\Cygwin64\bin\bash test.sh I have also tried this: C:\Cygwin64\bin\bash "C:\Cygwin64\bin\test.sh" Needless to say that the windows box has Cygwin... (7 Replies)
Discussion started by: Xterra
7 Replies

2. Shell Programming and Scripting

How to call a bash script with positional parameters?

Hi, I have a script which will be executed using the below command, bin/nutch crawl urls -dir /data/test/ bin/nutch - Script file crawl, urls, /data/test/ - Parameters -dir - Option The above script should executed from a shell script named test.sh. I have the below code to execute... (2 Replies)
Discussion started by: vel4ever
2 Replies

3. Shell Programming and Scripting

[solved] using backticks to call bash from perl

Hi all, Here is my code: my $x = `bash -c \" ls -l filename | awk '{print \$5}'\"`; print "$x\n"; This will run the first part of the bash script but not the awk command. It therefore gives output of: -rw-r--r-- 1 root root 13619200 2012-04-25 08:16 filename I am actually trying to... (0 Replies)
Discussion started by: free2rhyme2k
0 Replies

4. Shell Programming and Scripting

How to call a bash command from within a perl script?

In a bash script, one can call a perl command in the following manner, where "myperlcommand" is a perl command. perl -e 'myperlcommand(arguments)' perl -e 'print("UUUU"x4)' Now, how can one call a bash command from within a perl script? (Suppose that mybashcommand is a bash... (1 Reply)
Discussion started by: LessNux
1 Replies

5. Shell Programming and Scripting

How to call multiple variables in bash !!

Hi all , I have a file with below data , bash#cat file.txt user1 amount1 status1 user2 amount2 status2 user3 amount3 status3 user4 amount4 status4 . . . Now i have a command to be executed with above values like below , ./errorcheck -u user1 -a amount1 -s status1 ... (3 Replies)
Discussion started by: gnanasekar_beem
3 Replies

6. Shell Programming and Scripting

error when call function in bash script

Dear all, Could you please advice as I when call function i found the following error " refills: command not found" note that refills is function name. following also the function and how i call it function refills { echo "formatting refills and telepin" >> $log awk -F,... (20 Replies)
Discussion started by: ahmed.gad
20 Replies

7. Shell Programming and Scripting

how to call a bash script using perl

Hi I m new to perl. I m trying to write a perl script that calls a bash script; does anyone have a script already that they can provide or help me out? Thanks a lot. (2 Replies)
Discussion started by: adnan786
2 Replies

8. Shell Programming and Scripting

Bash: how to call function having it's name in variable?

Hello. Looking for a method of modularizing my bash script, I am stuck with such a problem. For example, I have: MODULE_NAME="test" FUNCTION_NAME="run" How do I can a function with name test_run? (4 Replies)
Discussion started by: FractalizeR
4 Replies
Login or Register to Ask a Question