I'm having trouble using IgnoreReadOnlyRecommended

I have Excel 2010.  The following vbscript file is executed by a scheduled task.  It opens a file to update it, save and close.  The file has the "read-only recommended" option on and my script must answer this prompt with "no" which is not the default.
Option Explicit
Dim objXL
Set objXL = WScript.CreateObject("Excel.Application")
With objXL
	.DisplayAlerts = False	
	.WorkBooks.Open FileName:="S:\Schedule\EngDates.xlsm", ReadOnlyRecommended:=False, IgnoreReadOnlyRecommended:=True
	.DisplayAlerts = TRUE
	.Visible = TRUE ' Optional
	.Run "EngDates.xlsm!UpdateDash"
	.ActiveWorkbook.Close(True)
	.Quit
End With
Set objXL = Nothing

Open in new window

I have tried several different syntax formats, with and without parentheses, and nothing has worked yet.
When I run this script, I get an error as seen in the attached file.  Does anyone see the problem with my syntax?  
Thanks!
The error that occurs when I run my script
Brennan BrauenAsked:
Who is Participating?
 
Brennan BrauenAuthor Commented:
Found it!!  Saw this in a post:

Note: " In VBScript, arguments must be supplied in the order specified by the procedure. " which implies that naming parameters is not an option, thus they must be in the order specified, so if you have to skip a parameter, you must put the comma in to separate parameters.

Had to change my OPEN statement to:
.WorkBooks.Open "S:\Schedule\EngDates.xlsm",,False,,,,True
where the False is the ReadOnly parameter and the True is for the IgnoreReadOnlyRecommended parameter.

Thanks again!
0
 
ShumsDistinguished Expert - 2017Commented:
Hi,

Try changing .DisplayAlert to Application.DisplayAlert
Dim objXL
Set objXL = WScript.CreateObject("Excel.Application")
With objXL
        Application.DisplayAlerts = False
        .Workbooks.Open Filename:="S:\Schedule\EngDates.xlsm", ReadOnlyRecommended:=False, IgnoreReadOnlyRecommended:=True
        Application.DisplayAlerts = True
        .Visible = True ' Optional
        .Run "EngDates.xlsm!UpdateDash"
        .ActiveWorkbook.Close (True)
        .Quit
End With
Set objXL = Nothing

Open in new window

0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Shums, objXL is an Excel.Application object. Further, you cannot just use Application in VBS, you need to reference it to an object.
And it isn't causing the error anyway.
1
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
For debugging it is a good idea to run that code in VBA, e.g. Excel or Word, applying few modifications:
Option Explicit
Sub test()
Dim objXL
Set objXL = Excel.Application
With objXL
  .DisplayAlerts = False
  .Workbooks.Open Filename:="S:\Schedule\EngDates.xlsm", ReadOnlyRecommended:=False, IgnoreReadOnlyRecommended:=True
  .DisplayAlerts = True
  .Visible = True ' Optional
  .Run "EngDates.xlsm!UpdateDash"
  .ActiveWorkbook.Close (True)
  .Quit
End With
Set objXL = Nothing
End Sub

Open in new window

That allows for giving suggestions on parameters, enables some checks and provides context sensitive help. You can also run code stepwise and/or set breakpoints, then check variable contents, ...

The issue is in ReadOnlyRecommended:=False - I suppose you meant ReadOnly:=False
0
 
Brennan BrauenAuthor Commented:
Qlemo, Thanks.  I ran step by step in VBA within Excel and it ran fine.  I did change to parameter to ReadOnly.  But when I ran my script directly it still errored out.  Must be a script syntax issue.

Shums, thanks for offering a suggestion.
0
 
Brennan BrauenAuthor Commented:
I found the answer by doing further research/googling.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.