0

I have a .csv file that will be generated frequently and named using timestamp. I need to run a macro in it and update the .csv file. I used this solution Run Excel Macro from Outside Excel Using VBScript From Command Line for running my macro, but my problem is I'm unable to save the .csv file without the macros enabled in it and the changes being saved in it. I have only one sheet of the csv file. Thanks for the help! This is the code I'm using, (got from that link):

   Dim oFSO
   Dim oShell, oExcel, oFile, oSheet
   Set oFSO = CreateObject("Scripting.FileSystemObject")
   Set oShell = CreateObject("WScript.Shell")
   Set oExcel = CreateObject("Excel.Application")
   Set wb2 = oExcel.Workbooks.Open("D:\.....\PERSONAL.XLSB") 'Specify     foldername here 

   oExcel.DisplayAlerts = False

   For Each oFile In oFSO.GetFolder("D:\..\Output1\").Files
      If LCase(oFSO.GetExtensionName(oFile)) = "csv" Then
 
         With oExcel.Workbooks.Open(oFile, 0, True, , , , True, , , , False, , False)
         oExcel.Run wb2.Name & "!final1"
         
         End With
      End If
   Next
Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
  • https://stackoverflow.com/questions/10551353/saving-excel-worksheet-to-csv-files-with-filenameworksheet-name-using-vb have a look here – Luuklag Aug 08 '17 at 08:05

1 Answers1

0

a csv file is a text file. open it with a text editor and you will see.

it has no functionality to have a macro embedded inside it.

you need to have the macro inside an excel file, and have it do the work that you need

jsotola
  • 2,238
  • 1
  • 10
  • 22
  • Hi Thanks for the reply!. I'm trying to run the macro from the personal workbook and I think "With oExcel.Workbooks.Open(oFile, 0, True, , , , True, , , , False, , False)" opens my .csv file runs the macro in it. If I use oExcel.Save , during runtime it is asking me to save the edited file. I need this to be saved automatically. – Clueless Aug 08 '17 at 07:54