question on proper method for opening a read only workbook from vbs/vba

mike p
06-18-2010, 12:40 PM
Working on a script that puts a subset of data from a large excel database workbook into a smaller version of the same (strips some of the data). I am using

Set objWorkbook = objExcel.Workbooks.Open(FileName)

to open the workbook. The parent workbook is password protected and I would like to open as read only and I am having some trouble figuring out the proper form this statement should take to enable opening in that mode. (Don't want to have to click the read only button on the pop-up). I have tried adding ",readOnly:=TRUE" into the open statement but it returns an error (says it expects a ")").

Any thoughts are appreciated. This in Office 2007 BTW.

Thanks,

Mike

Colin Legg
06-18-2010, 01:22 PM
Hi,

Like this:

Set objWorkbook = objExcel.Workbooks.Open(Filename:=vFileName, ReadOnly:=True, Password:=vPassword)

Hope the helps...

mike p
06-18-2010, 05:05 PM
I copied your code into my doc, but no dice. It gives the same error. Expected ")" at character 51, which is the colon before my actual filename location. For some reason it thinks the function is done after the filename is entered. Any other thoughts?

Thanks,

Mike

Colin Legg
06-19-2010, 06:07 AM
Hi Mike,

Just noted this is VBS, not VBA. Try this:

Set objWorkbook = objExcel.Workbooks.Open(vFileName, , True, , vPassword)


HTH,

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum