Using VBS to open Excel spreadsheet with write access

Rick Crosby 40 Reputation points
2026-09-13T15:34:31.2366667+00:00

I'm looking for assistance getting a vbs script to work with Task Scheduler on a new PC I've recently bought and configured. This script works fine when I manually run it, but it not working properly when I use Task Scheduler to run it. Also, this script worked fine with Task Scheduler on an older machine that I've replaced. My new machine is a Win 11 machine and the older, replaced machine was a Win 10 machine.

What this script does is to open an Excel spreadsheet and run a couple macros. This script runs at night so I have it set to run whether the user is logged on or not. Other environmental factors are: PC is running Win 11; Excel is an Office 2019 version installed on the machine; the vbs statement I'm using is "Call objExcel.Workbooks.Open(WkbMain, False, False)".

I've determined that this statement is opening the spreadsheet, but It's opening it for read only, which prevents the script and macro's from working properly.

Again, this worked fine on the last machine, and it works fine if I run it manually, but not with Scheduler. Task Scheduler I believe runs things as an administrator, so it shouldn't be requesting permission to run via GUI (which I don't see when I run it from within Scheduler).

Any suggestions? Settings on the worksheet file, in Excel, or in Scheduler?

Developer technologies | VB
0 comments No comments

Answer accepted by question author
Jay Pham (WICLOUD CORPORATION) 4,680 Reputation points Microsoft External Staff Moderator
2026-09-14T02:02:21.61+00:00

Hi @Rick Crosby ,

Please let me know how the tests suggested by Marcin go, particularly whether the task works with “Run only when user is logged on.”

To add some context on why this happens: when a task is set to “Run whether user is logged on or not,” it runs in a non interactive session with no loaded user desktop and a limited Office profile. Excel automation depends on that profile for things like temporary folders, HKEY_CURRENT_USER settings, and file locking. If Excel cannot create its lock file next to the workbook in that session, it silently falls back to opening the file as read only instead of returning an error. That is why the same script behaves differently between a manual run and a scheduled run, and why the Open(WkbMain, False, False) call is not the cause here.

If the issue persists, please share:

  • The workbook’s storage location, local drive or network share. Network shares and mapped drives are a common failure point because mapped drives are not available in a non interactive session, so a UNC path is required.
  • The result of the ReadOnly check right after the workbook is opened.
  • Any error message from the macro or the save operation.
  • The account the task runs under, and whether “Run with highest privileges” is enabled.

Also worth confirming that the account running the task has Modify or Write permission on the folder containing the workbook, not just on the workbook itself, since Excel needs to create the lock file in that folder.

These details will help me narrow down the cause.

Thank you.

Was this answer helpful?

1 person found this answer helpful.

Answer accepted by question author
Marcin Policht 109.7K Reputation points MVP Volunteer Moderator
2026-09-13T16:16:06.17+00:00

Considering that Excel successfully opens the correct workbook, you might want to focus on the difference between the interactive session and the Task Scheduler session rather than the file path.

Test by changing the task temporarily from "Run whether user is logged on or not" to "Run only when user is logged on." If the workbook then opens normally and the macros work, that indicates the problem is the noninteractive Task Scheduler session. Excel desktop automation can behave differently when launched without an interactive Windows desktop, particularly with the user's Office profile, HKEY_CURRENT_USER, temporary folders, and file locking.

Also verify that the task is running under exactly the same Windows account that you use when manually running the VBS. On the General tab, enable "Run with highest privileges." This does not automatically grant file permissions, so the account must also have Modify/Write permissions on the folder containing the workbook. Excel needs to create its temporary lock file there.

I would also populate Task Scheduler's "Start in (optional)" field with the folder containing the VBS/workbook, without quotation marks. This eliminates differences in the working directory between manual execution and Task Scheduler.

You can confirm what Excel is actually doing by checking the workbook immediately after opening it:

Set objWorkbook = objExcel.Workbooks.Open(WkbMain, False, False)
WScript.Echo "ReadOnly = " & objWorkbook.ReadOnly

If this reports True only when the task runs, then the VBS is not requesting read-only mode. Excel is choosing read-only because it cannot obtain the required write/lock access in that execution environment.


If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

hth

Marcin

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.