rk_19
Structural
- Aug 7, 2012
- 71
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