VBScript to open a Read-only file, execute a macro and save the file with the same name and in the same location

Omaestro

New Member
Joined
Jan 20, 2017
Messages
7
[FONT=&quot]Hello,[/FONT]
[FONT=&quot]I am currently writing a VBScript in order to schedule it to run twice everyday. The goal of the Script is to open a Read-only Excel file, execute a macro and afterwards save the file with the same name. It is extremely important that the file is saved with the same name, so I don't have to change the script each time I want to run it.[/FONT]
[FONT=&quot]After looking it up on some websites, I came up with the following code:[/FONT]
[FONT=&quot]
Dim xlApp, xlBook SetAttribute "C:\Users\e322016\Downloads\Book1.xlsm", vbNormal Set xlApp = CreateObject("Excel.Application") xlApp.DisplayAlerts = False Set xlBook = xlApp.Workbooks.Open("C:\Users\e322016\Downloads\Book1.xlsm", 0, True)[/FONT]
[FONT=&quot]xlApp.Run "Macro1"[/FONT]
[FONT=&quot]xlbook.Save xlBook.Close False set xlBook = Nothing[/FONT]
[FONT=&quot]xlApp.Quit Set xlApp = Nothing[/FONT]
[FONT=&quot]WScript.Echo "Finished." WScript.Quit[/FONT]
[FONT=&quot]
However, this code gives me the Error Code 800A000D regarding the SetAttribute function. I have tried to rewrite it a couple of times, but I still haven't found a solution to the problem.

[/FONT]
[FONT=Segoe UI, Arial, sans-serif]To [/FONT]provide more context: The excel file I am mentioning, updates the online performance of different products that are currently in promotion. The goal of the file is to be in the company network where every member of the selected network can check their items' performance.


[FONT=&quot]Thanks in advance! [/FONT]
 

Some videos you may like

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Watch MrExcel Video

Forum statistics

Threads
1,127,678
Messages
5,626,227
Members
416,169
Latest member
DROP_DATABASE_MrExel

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
Top