Using VBS to open Excel spreadsheet with write access

Rick Crosby 0 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

2 answers

Sort by: Most helpful
  1. Jay Pham (WICLOUD CORPORATION) 4,435 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.”

    If the issue persists, please share the workbook’s storage location (local drive, network share) the ReadOnly check result, and any error message from the macro or save operation. These details will help me narrow down the cause.

    Thank you.

    Was this answer helpful?

    0 comments No comments

  2. Marcin Policht 107.5K 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?


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.