ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Controlling Word from Excel (https://www.excelbanter.com/excel-programming/302780-controlling-word-excel.html)

Paul Haywood

Controlling Word from Excel
 
I am trying to open a Word document from a toolbar I have constructed
in Excel.

I would like my code to check to see whether an instance of Word is
already running and if so just open the document specified in
'Documents.Open Filename:="

I'm having quite a bit of trouble with this at the moment so any help
would be appreciated.

Thanks

papou[_9_]

Controlling Word from Excel
 
Hi Paul
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err < 0 Then Set objWord = CreateObject("Word.Application")

HTH
Cordially
Pascal

"Paul Haywood" a écrit dans le message de
om...
I am trying to open a Word document from a toolbar I have constructed
in Excel.

I would like my code to check to see whether an instance of Word is
already running and if so just open the document specified in
'Documents.Open Filename:="

I'm having quite a bit of trouble with this at the moment so any help
would be appreciated.

Thanks




Paul Haywood

Controlling Word from Excel
 
Thanks for your reply and this does help but I'm having inconsistent
results opening the Word document, sometimes it opens and sometimes it
doesn't. I have included the code for your perusal. Any help would
be greatly appreciated.

Sub Open_Tips()

On Error Resume Next

Set objWord = GetObject(, "Word.Application")

If Err < 0 Then Set objWord = CreateObject("Word.Application")

objWord.Visible = True
objWord.Activate

ChangeFileOpenDirectory "M:\Finance\General\Management
Information\Extras\"
Documents.Open Filename:="""XL Tips.doc""",
ConfirmConversions:=False, _
ReadOnly:=True, AddToRecentFiles:=False, PasswordDocument:="",
_
PasswordTemplate:="", Revert:=False,
WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto

objWord = Nothing

End Sub

Regards

"papou" wrote in message ...
Hi Paul
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err < 0 Then Set objWord = CreateObject("Word.Application")

HTH
Cordially
Pascal

"Paul Haywood" a écrit dans le message de
om...
I am trying to open a Word document from a toolbar I have constructed
in Excel.

I would like my code to check to see whether an instance of Word is
already running and if so just open the document specified in
'Documents.Open Filename:="

I'm having quite a bit of trouble with this at the moment so any help
would be appreciated.

Thanks


papou[_9_]

Controlling Word from Excel
 
Hi Paul
Some slight amendments/suggestions:
1 - objWord.Activate is not necessary
2 - What is the ChangeFileOpenDirectory?
I would suggest that this is not necessary since you could include the path
in: the opening process.
3 - When opening the file you are not using the objWord so this may be the
reason for its not working properly.
Therefore I would suggest:
objWord.Documents.Open Filename:="M:\Finance\General\Management_
Information\Extras\XL Tips.doc"

HTH
Cordially
Pascal

"Paul Haywood" a écrit dans le message de
om...
Thanks for your reply and this does help but I'm having inconsistent
results opening the Word document, sometimes it opens and sometimes it
doesn't. I have included the code for your perusal. Any help would
be greatly appreciated.

Sub Open_Tips()

On Error Resume Next

Set objWord = GetObject(, "Word.Application")

If Err < 0 Then Set objWord = CreateObject("Word.Application")

objWord.Visible = True
objWord.Activate

ChangeFileOpenDirectory "M:\Finance\General\Management
Information\Extras\"
Documents.Open Filename:="""XL Tips.doc""",
ConfirmConversions:=False, _
ReadOnly:=True, AddToRecentFiles:=False, PasswordDocument:="",
_
PasswordTemplate:="", Revert:=False,
WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto

objWord = Nothing

End Sub

Regards

"papou" wrote in message

...
Hi Paul
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err < 0 Then Set objWord = CreateObject("Word.Application")

HTH
Cordially
Pascal

"Paul Haywood" a écrit dans le message de
om...
I am trying to open a Word document from a toolbar I have constructed
in Excel.

I would like my code to check to see whether an instance of Word is
already running and if so just open the document specified in
'Documents.Open Filename:="

I'm having quite a bit of trouble with this at the moment so any help
would be appreciated.

Thanks





All times are GMT +1. The time now is 10:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com