Excel VBS Script Problem

JoeyGaspard

Board Regular
Joined
Jul 22, 2019
Messages
164
I am trying to write this script that will open excel, run a macro, then save the specified worksheet as a csv, the process works up to the point of saving the csv. I appreciate any help or insight! Below is the script and also a screenshot of the error I am getting:

Option Explicit

Dim xlApp, xlBook

Set xlApp = CreateObject("Excel.Application")
xlApp.visible=true
Set xlBook = xlApp.Workbooks.Open("c:\adp\UploadV1.xlsm", 0, True)
xlApp.Run "ProcessTime"

Set objWorksheet = objWorkbook.Worksheets("Upload")
objWorksheet.SaveAs "c:\ADP\PunchReport.csv", xlCSV

objExcel.Quit

xlBook.Close
xlApp.Quit

Set xlBook = Nothing
Set xlApp = Nothing

1666791170152.png
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
My apologies, I posted the wrong script, this is the one, and the error is the same:


Set objExcel = CreateObject("Excel.Application")
objexcel.application.Run "'C:\ADP\Uploadv1.xlsm'!Module1.ProcessTime"
objExcel.DisplayAlerts = False

Set objWorksheet = objWorkbook.Worksheets("Upload")
objWorksheet.SaveAs "c:\ADP\PunchReport.csv", xlCSV

objExcel.Application.Quit
Set objExcel = Nothing
 
Upvote 0
Good to hear you got the solution.

If you would like to post the solution then it is perfectly fine to mark your post as the solution to help future readers. Otherwise, please do not mark a post that doesn't contain a solution.
 
Upvote 0
Good to hear you got the solution.

If you would like to post the solution then it is perfectly fine to mark your post as the solution to help future readers. Otherwise, please do not mark a post that doesn't contain a solution.
Well, hate to say it, but I didnt solve it. I researched more and was able to create a standalone script that would save the file, but when I add it to the script to open and run the macro, it wont save the file anymore, not sure what i have done wrong, VBS is very new to me, here is what I have in case you may see the issue? I realize that I am starting and stopping excel twice, but this is just where I am trying to trouble shoot it.

Set objExcel = CreateObject("Excel.Application")
objexcel.application.Run "'C:\ADP\Uploadv1.xlsm'!Module1.ProcessTime"
objExcel.DisplayAlerts = False
objExcel.Application.Quit
Set objExcel = Nothing
Const xlCSV = 6
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\ADP\UploadV1.xlsm")
objExcel.DisplayAlerts = FALSE
objExcel.Visible = TRUE
objExcel.Quit
 
Upvote 0
Well, hate to say it, but I didnt solve it. I researched more and was able to create a standalone script that would save the file, but when I add it to the script to open and run the macro, it wont save the file anymore, not sure what i have done wrong, VBS is very new to me, here is what I have in case you may see the issue? I realize that I am starting and stopping excel twice, but this is just where I am trying to trouble shoot it.

Set objExcel = CreateObject("Excel.Application")
objexcel.application.Run "'C:\ADP\Uploadv1.xlsm'!Module1.ProcessTime"
objExcel.DisplayAlerts = False
objExcel.Application.Quit
Set objExcel = Nothing
Const xlCSV = 6
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\ADP\UploadV1.xlsm")
objExcel.DisplayAlerts = FALSE
objExcel.Visible = TRUE
objExcel.Quit
Sorry, here is the code I am using, I left a line out:
Set objExcel = CreateObject("Excel.Application")
objexcel.application.Run "'C:\ADP\Uploadv1.xlsm'!Module1.ProcessTime"
objExcel.DisplayAlerts = False
objExcel.Application.Quit
Set objExcel = Nothing
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\ADP\UploadV1.xlsm")
objWorksheet.SaveAs "c:\ADP\PunchReport.csv", xlCSV
objExcel.DisplayAlerts = FALSE
objExcel.Visible = TRUE
objExcel.Quit

And here is the error:
1666795088507.png
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top