View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Mark Seger Mark Seger is offline
external usenet poster
 
Posts: 13
Default How to write a macro to open a file read-only?

Ok I just tried this. Upon closer inspection it looks 'readonly' is a
readonly property, it can't be set. So I'm back to where I started.
But keep those suggestions coming...
-mark

Peter T wrote:

Hi Mark,

Workbook.Open does indeed have a ReadOnly argument that can be used the way
JMB suggested. See help.

Workbook also has a ReadOnly property that you can read, eg

bRdOnly = Activeworkbook.readonly

I don't follow what you want or don't want to do. However one thing you
can't do is save a readonly workbook, eg one that's deliberatly been opened
as readonly, opened for a second time, or already open in another instance
of Excel.

If your macro is trying to do that, check the readonly property as above.

Regards,
Peter T

"Mark Seger" wrote in message
...

good guess but wrong one. There is no readonly argument. To verify
this I recorded a macro of opening a file, closed it and added in your
suggestion even though the help for that function doesn't list it (nor
does the object model). Sure enough, when I try to run it I get the
error "Named Argument Not Found".

As I said below in my base posting, when you open a file in readonly
mode NOTHING is recorded in the macro and if you try running the macro
the file does not open read-only. 8-(

-mark

JMB wrote:


Workbooks.Open should have a readonly named argument.

Sub testopen()
Const path As String = "C:\temp\test\abccompany#1.xls"

Workbooks.Open Filename:=path, ReadOnly:=True
End Sub



"Mark Seger" wrote:



The first thing I did to try this was manually open a file read-only
while in record-macro mode and save the macro. There is nothing in the
macro to indicate the file should be opened read-only. In fact, if I
then reopen the file using the macro it is NOT opened read-only.

So, the big question is is there no way to open a file read-only via a
macro OR is the 'record macro' function busted. btw - I did check the
open methods and there are no parameters documented to control this
either. I also discovered a 'permissions' object that sounds like if
might help, but there has been nothing recorded in my macro and so don't
see any good examples of how I might use it.

-mark