Invoke an .exe file using macro in excel
Invoke an .exe file using macro in excel
(OP)
Hi, i am trying to create an macro enabled excel file, in which , upon hitting the button, the excel gets saved to 'data.csv' into the same folder and an exe file is invoked (which is again in same folder) which will access the 'data.csv' for its inputs. i prepared this, however, upon hitting the button - i can an error as shown in attachment. the directory shown in that screenshot is the directory in which the exe was created initially - this directory has nothing to do with current working directory. could some one look into this. the code is shown below. i tried running the .exe file seperately and it ran seamless - so no issue with exe file - something to do with communication between macro and exe ??? thanks
Public Sub Save_CSV()
Dim MyPATH As String
Dim FileNAME As String
Dim FilePath As String
Dim OldPath As String
Dim RetVal As Variant
Dim stat As Integer
'*
FilePath = ActiveWorkbook.path & "/dynjackup.exe"
OldPath = CurDir
MyPATH = ActiveWorkbook.path
FileNAME = ActiveWorkbook.Name
FileNAME = Left(FileNAME, Len(FileNAME) - 4) ' REMOVE XLS EXTENSION
'FileNAME = FileNAME & "csv" ' ADD CSV EXTENSION
FileNAME = "data.csv" ' any name can be set here
Application.DisplayAlerts = False ' REMOVE DISPLAY MESSAGE: PREVIOUS FILE WILL BE ERASED
ActiveWorkbook.SaveAs FileNAME:= _
MyPATH & "\" & FileNAME, FileFormat:=xlCSV, _
CreateBackup:=False
'
OldPath = CurDir
'
' Call ChangeCurrentDir(ActiveWorkbook.path, stat)
RetVal = Shell(FilePath, vbNormalFocus)
'Call ChangeCurrentDir(OldPath, stat)
'ActiveWindow.Close
'Application.DisplayAlerts = True ' Restore DISPLAY MESSAGE
End Sub





RE: Invoke an .exe file using macro in excel
https://newtonexcelbach.wordpress.com/2016/06/30/r...
Doug Jenkins
Interactive Design Services
http://newtonexcelbach.wordpress.com/
RE: Invoke an .exe file using macro in excel
FilePath = ActiveWorkbook.path & "/dynjackup.exe"
contains a fwd slash rather than backslash.
Your code also does not provide any parameters to the .exe file. It doesn't "communicate" with the .exe at all. It simply tells the OS to execute it. Although as I said I don't know how it doesn't throw an error there due to the fwd slash.
-handleman, CSWP (The new, easy test)
RE: Invoke an .exe file using macro in excel
https://newtonexcelbach.wordpress.com/2016/07/04/c...
Doug Jenkins
Interactive Design Services
http://newtonexcelbach.wordpress.com/
RE: Invoke an .exe file using macro in excel
RE: Invoke an .exe file using macro in excel
How does the .exe work? All your code is doing is same as double-clicking the .exe file in Windows. It's not specifying where the .exe should look for its data.
-handleman, CSWP (The new, easy test)
RE: Invoke an .exe file using macro in excel
Do you have access to the source code for the exe? Can it take a command line parameter? If not, can you add in code to take the command line parameter as the file you are generating?
RE: Invoke an .exe file using macro in excel
https://msdn.microsoft.com/en-us/library/office/gg...
http://stackoverflow.com/questions/2784367/capture...
RE: Invoke an .exe file using macro in excel
RE: Invoke an .exe file using macro in excel
TTFN (ta ta for now)
I can do absolutely anything. I'm an expert! https://www.youtube.com/watch?v=BKorP55Aqvg
FAQ731-376: Eng-Tips.com Forum Policies forum1529: Translation Assistance for Engineers Entire Forum list http://www.eng-tips.com/forumlist.cfm
RE: Invoke an .exe file using macro in excel
RE: Invoke an .exe file using macro in excel
TTFN (ta ta for now)
I can do absolutely anything. I'm an expert! https://www.youtube.com/watch?v=BKorP55Aqvg
FAQ731-376: Eng-Tips.com Forum Policies forum1529: Translation Assistance for Engineers Entire Forum list http://www.eng-tips.com/forumlist.cfm
RE: Invoke an .exe file using macro in excel
RE: Invoke an .exe file using macro in excel
RE: Invoke an .exe file using macro in excel
Did you look at the link I posted in my first post in this thread?
It seems to me that it gives you everything you need to know to do what you want to do, but if it doesn't, please let me know what is lacking, or what doesn't work.
Also, have you tried stepping through the code in the VBA editor, to make sure it is generating the right text (path names, command lines etc)?
Doug Jenkins
Interactive Design Services
http://newtonexcelbach.wordpress.com/
RE: Invoke an .exe file using macro in excel
What exactly are you double-clicking when things work in the way that you won't describe to us?
How does the .exe expect to get the location of the .csv?
RE: Invoke an .exe file using macro in excel
If you are using IVF, have a look at GetModuleFilename and GetModuleHandle.
RE: Invoke an .exe file using macro in excel
RE: Invoke an .exe file using macro in excel
RE: Invoke an .exe file using macro in excel
https://newtonexcelbach.wordpress.com/2016/06/30/r...