PC Review


Reply
Thread Tools Rate Thread

Can only open Read-Only Word documents from Excel using VBA

 
 
Dave.Punk.Emo
Guest
Posts: n/a
 
      6th Aug 2007
Ok, I'm trying to open and update a MS Word document from Excel using
VBA, but everytime I try to open it, it loads as a Read Only Document,
giving me the message that this file is locked for use by myself, and
thus not allowing me to save it. I'm using this code to open it (the
SendKeys does not appear to make any difference to this message):

Sub Button13_Click()
Dim wdApp As Object
Dim wdDoc As Object
Dim sFname As String

sFname = "R:\SALES\Quote Generators\Quotes\2 Pass Tray\2 Pass Tray
Quote.doc" 'File Location

If sFname = "R:\SALES\Quote Generators\Quotes\2 Pass Tray\2 Pass
Tray Quote.doc" Then

Set wdApp = CreateObject("Word.Application")
wdApp.Documents.Open Filename:="R:\SALES\Quote Generators
\Quotes\2 Pass Tray\2 Pass Tray Quote.doc" 'Opens File
SendKeys "{Left} {Enter}, False" 'Updates File
End If
End Sub


Can anyone help me to be able to open it as a non-read-only file...?

 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      6th Aug 2007
Sounds like you may already have created a Word instance and opened that
file.

Cheek if Word is already running.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Dave.Punk.Emo" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Ok, I'm trying to open and update a MS Word document from Excel using
> VBA, but everytime I try to open it, it loads as a Read Only Document,
> giving me the message that this file is locked for use by myself, and
> thus not allowing me to save it. I'm using this code to open it (the
> SendKeys does not appear to make any difference to this message):
>
> Sub Button13_Click()
> Dim wdApp As Object
> Dim wdDoc As Object
> Dim sFname As String
>
> sFname = "R:\SALES\Quote Generators\Quotes\2 Pass Tray\2 Pass Tray
> Quote.doc" 'File Location
>
> If sFname = "R:\SALES\Quote Generators\Quotes\2 Pass Tray\2 Pass
> Tray Quote.doc" Then
>
> Set wdApp = CreateObject("Word.Application")
> wdApp.Documents.Open Filename:="R:\SALES\Quote Generators
> \Quotes\2 Pass Tray\2 Pass Tray Quote.doc" 'Opens File
> SendKeys "{Left} {Enter}, False" 'Updates File
> End If
> End Sub
>
>
> Can anyone help me to be able to open it as a non-read-only file...?
>



 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      6th Aug 2007
I mean check of course.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Dave.Punk.Emo" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Ok, I'm trying to open and update a MS Word document from Excel using
> VBA, but everytime I try to open it, it loads as a Read Only Document,
> giving me the message that this file is locked for use by myself, and
> thus not allowing me to save it. I'm using this code to open it (the
> SendKeys does not appear to make any difference to this message):
>
> Sub Button13_Click()
> Dim wdApp As Object
> Dim wdDoc As Object
> Dim sFname As String
>
> sFname = "R:\SALES\Quote Generators\Quotes\2 Pass Tray\2 Pass Tray
> Quote.doc" 'File Location
>
> If sFname = "R:\SALES\Quote Generators\Quotes\2 Pass Tray\2 Pass
> Tray Quote.doc" Then
>
> Set wdApp = CreateObject("Word.Application")
> wdApp.Documents.Open Filename:="R:\SALES\Quote Generators
> \Quotes\2 Pass Tray\2 Pass Tray Quote.doc" 'Opens File
> SendKeys "{Left} {Enter}, False" 'Updates File
> End If
> End Sub
>
>
> Can anyone help me to be able to open it as a non-read-only file...?
>



 
Reply With Quote
 
=?Utf-8?B?ZGFuaGF0dGFu?=
Guest
Posts: n/a
 
      10th Aug 2007
Hi Bob.

I was searching the forum to learn how to open a Word doc from an excel
macro and found this code from your post on 4/2/2007:

If Range("H1").Value = "Y" Then
Set oWordApp = CreateObject("Word.Application")
Set oDoc = oWordApp.Documents.Open("C:\personal\bob\doc1.doc")
'do something
Set oDoc = Nothing
oWordApp.Quit
Set oWordApp = Nothing
End If

It works, but I'm having the same problem as Dave here, and I have carefully
shut down Word but that doesn't help. I have a suspicion that perhaps you
could confirm. I'm trying to open a Word mail-merge document that reads from
the spreadsheet that holds the macro opening the Word doc. Any chance that
the passing connections are causing a conflict, and that's creating the
Read-Only problem? Please let me know what you think.

Thanks much - Dan.

"Bob Phillips" wrote:

> Sounds like you may already have created a Word instance and opened that
> file.
>
> Cheek if Word is already running.
>
> --
> HTH
>
> Bob
>
> (there's no email, no snail mail, but somewhere should be gmail in my addy)
>
> "Dave.Punk.Emo" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Ok, I'm trying to open and update a MS Word document from Excel using
> > VBA, but everytime I try to open it, it loads as a Read Only Document,
> > giving me the message that this file is locked for use by myself, and
> > thus not allowing me to save it. I'm using this code to open it (the
> > SendKeys does not appear to make any difference to this message):
> >
> > Sub Button13_Click()
> > Dim wdApp As Object
> > Dim wdDoc As Object
> > Dim sFname As String
> >
> > sFname = "R:\SALES\Quote Generators\Quotes\2 Pass Tray\2 Pass Tray
> > Quote.doc" 'File Location
> >
> > If sFname = "R:\SALES\Quote Generators\Quotes\2 Pass Tray\2 Pass
> > Tray Quote.doc" Then
> >
> > Set wdApp = CreateObject("Word.Application")
> > wdApp.Documents.Open Filename:="R:\SALES\Quote Generators
> > \Quotes\2 Pass Tray\2 Pass Tray Quote.doc" 'Opens File
> > SendKeys "{Left} {Enter}, False" 'Updates File
> > End If
> > End Sub
> >
> >
> > Can anyone help me to be able to open it as a non-read-only file...?
> >

>
>
>

 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      11th Aug 2007
Sounds possible Dan, but I would need to test it. I'll do that this weekend
if I get a chance.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"danhattan" <(E-Mail Removed)> wrote in message
news:48F7872A-EC9D-42D3-91CC-(E-Mail Removed)...
> Hi Bob.
>
> I was searching the forum to learn how to open a Word doc from an excel
> macro and found this code from your post on 4/2/2007:
>
> If Range("H1").Value = "Y" Then
> Set oWordApp = CreateObject("Word.Application")
> Set oDoc = oWordApp.Documents.Open("C:\personal\bob\doc1.doc")
> 'do something
> Set oDoc = Nothing
> oWordApp.Quit
> Set oWordApp = Nothing
> End If
>
> It works, but I'm having the same problem as Dave here, and I have
> carefully
> shut down Word but that doesn't help. I have a suspicion that perhaps you
> could confirm. I'm trying to open a Word mail-merge document that reads
> from
> the spreadsheet that holds the macro opening the Word doc. Any chance that
> the passing connections are causing a conflict, and that's creating the
> Read-Only problem? Please let me know what you think.
>
> Thanks much - Dan.
>
> "Bob Phillips" wrote:
>
>> Sounds like you may already have created a Word instance and opened that
>> file.
>>
>> Cheek if Word is already running.
>>
>> --
>> HTH
>>
>> Bob
>>
>> (there's no email, no snail mail, but somewhere should be gmail in my
>> addy)
>>
>> "Dave.Punk.Emo" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > Ok, I'm trying to open and update a MS Word document from Excel using
>> > VBA, but everytime I try to open it, it loads as a Read Only Document,
>> > giving me the message that this file is locked for use by myself, and
>> > thus not allowing me to save it. I'm using this code to open it (the
>> > SendKeys does not appear to make any difference to this message):
>> >
>> > Sub Button13_Click()
>> > Dim wdApp As Object
>> > Dim wdDoc As Object
>> > Dim sFname As String
>> >
>> > sFname = "R:\SALES\Quote Generators\Quotes\2 Pass Tray\2 Pass Tray
>> > Quote.doc" 'File Location
>> >
>> > If sFname = "R:\SALES\Quote Generators\Quotes\2 Pass Tray\2 Pass
>> > Tray Quote.doc" Then
>> >
>> > Set wdApp = CreateObject("Word.Application")
>> > wdApp.Documents.Open Filename:="R:\SALES\Quote Generators
>> > \Quotes\2 Pass Tray\2 Pass Tray Quote.doc" 'Opens File
>> > SendKeys "{Left} {Enter}, False" 'Updates File
>> > End If
>> > End Sub
>> >
>> >
>> > Can anyone help me to be able to open it as a non-read-only file...?
>> >

>>
>>
>>



 
Reply With Quote
 
Dave.Punk.Emo
Guest
Posts: n/a
 
      13th Aug 2007
On Aug 6, 7:35 pm, "Bob Phillips" <bob....@somewhere.com> wrote:
> Sounds like you may already have created a Word instance and opened that
> file.
>
> Cheek if Word is already running.
>
> --
> HTH
>
> Bob
>
> (there's no email, no snail mail, but somewhere should be gmail in my addy)
>
> "Dave.Punk.Emo" <Brydo.Sk...@gmail.com> wrote in message
>
> news:(E-Mail Removed)...
>
>
>
> > Ok, I'm trying to open and update a MS Word document from Excel using
> > VBA, but everytime I try to open it, it loads as a Read Only Document,
> > giving me the message that this file is locked for use by myself, and
> > thus not allowing me to save it. I'm using this code to open it (the
> > SendKeys does not appear to make any difference to this message):

>
> > Sub Button13_Click()
> > Dim wdApp As Object
> > Dim wdDoc As Object
> > Dim sFname As String

>
> > sFname = "R:\SALES\Quote Generators\Quotes\2 Pass Tray\2 Pass Tray
> > Quote.doc" 'File Location

>
> > If sFname = "R:\SALES\Quote Generators\Quotes\2 Pass Tray\2 Pass
> > Tray Quote.doc" Then

>
> > Set wdApp = CreateObject("Word.Application")
> > wdApp.Documents.Open Filename:="R:\SALES\Quote Generators
> > \Quotes\2 Pass Tray\2 Pass Tray Quote.doc" 'Opens File
> > SendKeys "{Left} {Enter}, False" 'Updates File
> > End If
> > End Sub

>
> > Can anyone help me to be able to open it as a non-read-only file...?- Hide quoted text -

>
> - Show quoted text -


What seems to happen is the first time the code is executed, it
creates an instance of word, and the second time it is executed, it
opens the file, as read only. Any ideas on how to fix this?

 
Reply With Quote
 
Dave.Punk.Emo
Guest
Posts: n/a
 
      13th Aug 2007
On Aug 13, 10:53 am, "Dave.Punk.Emo" <Brydo.Sk...@gmail.com> wrote:
> On Aug 6, 7:35 pm, "Bob Phillips" <bob....@somewhere.com> wrote:
>
>
>
>
>
> > Sounds like you may already have created aWordinstance and opened that
> > file.

>
> > Cheek ifWordis already running.

>
> > --
> > HTH

>
> > Bob

>
> > (there's no email, no snail mail, but somewhere should be gmail in my addy)

>
> > "Dave.Punk.Emo" <Brydo.Sk...@gmail.com> wrote in message

>
> >news:(E-Mail Removed)...

>
> > > Ok, I'm trying toopenand update a MSWorddocument fromExcelusing
> > > VBA, but everytime I try toopenit, it loads as a Read Only Document,
> > > giving me the message that this file is locked for use by myself, and
> > > thus not allowing me to save it. I'm using this code toopenit (the
> > > SendKeys does not appear to make any difference to this message):

>
> > > Sub Button13_Click()
> > > Dim wdApp As Object
> > > Dim wdDoc As Object
> > > Dim sFname As String

>
> > > sFname = "R:\SALES\Quote Generators\Quotes\2 Pass Tray\2 Pass Tray
> > > Quote.doc" 'File Location

>
> > > If sFname = "R:\SALES\Quote Generators\Quotes\2 Pass Tray\2 Pass
> > > Tray Quote.doc" Then

>
> > > Set wdApp = CreateObject("Word.Application")
> > > wdApp.Documents.OpenFilename:="R:\SALES\Quote Generators
> > > \Quotes\2 Pass Tray\2 Pass Tray Quote.doc" 'Opens File
> > > SendKeys "{Left} {Enter}, False" 'Updates File
> > > End If
> > > End Sub

>
> > > Can anyone help me to be able toopenit as a non-read-only file...?- Hide quoted text -

>
> > - Show quoted text -

>
> What seems to happen is the first time the code is executed, it
> creates an instance ofword, and the second time it is executed, it
> opens the file, as read only. Any ideas on how to fix this?- Hide quoted text -
>
> - Show quoted text -


I managed to fix it by changing the code to:


Sub Button13_Click()
Dim wdApp As Object
Dim wdDoc As Object
Dim sFname As String

sFname = "R:\SALES\Quote Generators\Quotes\2 Pass Tray\2 Pass Tray
Quote.doc" 'File Location

If sFname = "R:\SALES\Quote Generators\Quotes\2 Pass Tray\2 Pass
Tray Quote.doc" Then

Set wdApp = CreateObject("Word.Application")

wdApp.Documents.Open Filename:="R:\SALES\Quote Generators
\Quotes\2 Pass Tray\2 Pass Tray Quote.doc" 'Opens File
wdApp.Visible = True 'Added this
lline of code
SendKeys "{Left} {Enter}" 'Updates File
End If
End Sub


Thanks for all the help

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Read/write excel and word 2007 documents from another application mco3006 Microsoft Excel Misc 0 27th Apr 2010 10:18 AM
why do my word documents automatically open as read only =?Utf-8?B?bWlyaWFt?= Microsoft Word Document Management 3 8th Jan 2010 04:40 PM
Word changes open documents to Read Only - why? Millie Microsoft Word Document Management 9 22nd Oct 2008 04:18 PM
Excel and Word documents do not open =?Utf-8?B?Sm9obg==?= Microsoft Dot NET 0 5th Apr 2006 08:27 PM
Word documents always open read-only =?Utf-8?B?UmRlZ2Fu?= Microsoft Word Document Management 3 26th Nov 2004 11:32 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:02 PM.