View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default How to write a macro to open a file read-only?

are you suggesting I
could set the property of a workbook to readonly after I open it?


No - the readonly property is read only, as stated in help.

Afraid your additional comments has not shed any light on your issue, at
least not to me!

Regards,
Peter T

"Mark Seger" wrote in message
...
I hear what you're saying but maybe we're talking about two different
things and I guess I wasn't clear enough. Remember, I'm trying to do
this via macros. The diagnostic method I'm using to track this down is
to record a macro, perform an operation and then look to see what got
recorded. When I open an xls file I can see that 'workbook.open' is
indeed being executed as you suggest and it does indeed take a ReadOnly
parameter. However, if I open a text file it gets opened with
"Workbook.OpenText" and that doesn't take a ReadOnly parameter.

However loking at your example gives me hope - are you suggesting I
could set the property of a workbook to readonly after I open it? This
is certainly something you can't do via the user interface to excel, or
if you can I couldn't find it.

-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