Hi All,

I wasn't sure whether this should be a Word or Excel query so I have
cross-posted. Apologies if anyone objects!

I am using the following code in a module in Word to open an existing
Excel document:


Sub Open_Plan()

Dim xls As Object

Dim wrk As Object

Dim xlfilename As String

xlfilename = "F:\Alan\Plan.xls"

Set xls = CreateObject("Excel.Application")

xls.Visible = True

Set wrk = xls.workbooks.Open(FileName:=xlfilename, Updatelinks:=0,
ReadOnly:=False, Password:="password")

End Sub



This works fine, except that it seems to skip or ignore the 'ReadOnly
= FALSE' argument, and the file still opens as Read Only every time.

I am stumped as to how to get around this.

Thanks in advance for any help you can provide.

Alan.

Re: Opening Excel Workbook from Word using VBA - Always Read Only by Jezebel

Jezebel
Tue Nov 04 22:05:09 CST 2003

Have you checked in Windows Explorer to see if the file itself is read only
(came off a CD perhaps)?


"Alan" <alan@alan.alan> wrote in message
news:%23oyA8f0oDHA.964@TK2MSFTNGP10.phx.gbl...
>
> Hi All,
>
> I wasn't sure whether this should be a Word or Excel query so I have
> cross-posted. Apologies if anyone objects!
>
> I am using the following code in a module in Word to open an existing
> Excel document:
>
>
> Sub Open_Plan()
>
> Dim xls As Object
>
> Dim wrk As Object
>
> Dim xlfilename As String
>
> xlfilename = "F:\Alan\Plan.xls"
>
> Set xls = CreateObject("Excel.Application")
>
> xls.Visible = True
>
> Set wrk = xls.workbooks.Open(FileName:=xlfilename, Updatelinks:=0,
> ReadOnly:=False, Password:="password")
>
> End Sub
>
>
>
> This works fine, except that it seems to skip or ignore the 'ReadOnly
> = FALSE' argument, and the file still opens as Read Only every time.
>
> I am stumped as to how to get around this.
>
> Thanks in advance for any help you can provide.
>
> Alan.
>
>
>



Re: Opening Excel Workbook from Word using VBA - Always Read Only by Alan

Alan
Tue Nov 04 22:21:09 CST 2003

"Jezebel" <grocer@play.net> wrote in message
news:eZuQqH1oDHA.1948@TK2MSFTNGP12.phx.gbl...
>
> Have you checked in Windows Explorer to see if the file itself is
> read only (came off a CD perhaps)?
>

Hi Jezebel,

I should have stated up front that I had in fact checked that, but
good point to ask nevertheless.

Unfortunately, it is not that simple an answer for me!

Any other ideas?

Thanks,

Alan.




Re: Opening Excel Workbook from Word using VBA - Always Read Only by JGM

JGM
Tue Nov 04 23:54:28 CST 2003

Hi Alan,

Try changing
>Set wrk = xls.workbooks.Open(FileName:=xlfilename, Updatelinks:=0, _
> ReadOnly:=False, Password:="password")
for
Set wrk = xls.workbooks.Open(FileName:=xlfilename, Updatelinks:=0, _
WriteResPassword:="password")

If your original code opens the workbook all it means that it is not
protected against opening it, but against modification, which is a different
password. If you have two passwords, you will have to include both in the
arguments, even if it is the same password for opening and for modification.

Something like:
Set wrk = xls.workbooks.Open(FileName:=xlfilename, Updatelinks:=0, _
Password:="password", WriteResPassword:="password")

If you decalre both password like this, You do not need the ReadOnly
argument. Actually, the ReadOnly argument is to give you the option to open
a document through code and make it "Read Only" even if it has not been
protected by a password... In fact, without the password argument, the
ReadOnly argument is useless, and if you supply a password, why bother with
a ReadOnly argument... see what I mean?

Anyway, just my 2 cents!

HTH
Cheers!
--
_______________________________________
Jean-Guy Marcil
jmarcil@sympatico.ca

"Alan" <alan@alan.alan> a écrit dans le message de news:
uUEAGQ1oDHA.1960@TK2MSFTNGP12.phx.gbl...
> "Jezebel" <grocer@play.net> wrote in message
> news:eZuQqH1oDHA.1948@TK2MSFTNGP12.phx.gbl...
> >
> > Have you checked in Windows Explorer to see if the file itself is
> > read only (came off a CD perhaps)?
> >
>
> Hi Jezebel,
>
> I should have stated up front that I had in fact checked that, but
> good point to ask nevertheless.
>
> Unfortunately, it is not that simple an answer for me!
>
> Any other ideas?
>
> Thanks,
>
> Alan.
>
>
>



Re: Opening Excel Workbook from Word using VBA - Always Read Only by Alan

Alan
Wed Nov 05 18:19:20 CST 2003


"JGM" <no-spam@leaveme.alone> wrote in message
news:OaMiFC2oDHA.2000@TK2MSFTNGP10.phx.gbl...
>
> Try changing
>
>> Set wrk = xls.workbooks.Open(FileName:=xlfilename, Updatelinks:=0,
_
>> ReadOnly:=False, Password:="password")
>
> for
>
> Set wrk = xls.workbooks.Open(FileName:=xlfilename, Updatelinks:=0, _
> WriteResPassword:="password")
>
> If your original code opens the workbook all it means that it is not
> protected against opening it, but against modification, which is a
> different password. If you have two passwords, you will have to
> include both in the arguments, even if it is the same password for
> opening and for modification.
>
> _______________________________________
> Jean-Guy Marcil
> jmarcil@sympatico.ca
>

Hi Jean-Guy,

Thanks for your input.

I looked into this, but the password is definately only to open the
workbook, not just for modification.

I have got around this for the time being by having Word run a small
executable that I wrote that then opens excel as wanted.

Thank you for your input though - I may return to this when I have a
little more time, and I'll investigate your suggestion in detail.

Cheers,

Alan.