Controlling Word from Excel - whats wrong with this?

philR

Active Member
Joined
Feb 25, 2002
Messages
257
I am trying to open a word document from excel, find a bookmark within the document and type something there. Sounsd simple? Well, I can't get it to work. Maybe one of you can. Before I trash this stupid computer and get a pencil and a piece of paper instead.
Here is what I have got so far:

Set myWord = CreateObject("Word.Application")
myWord.Visible = True
myWord.documents.Open FileName:="C:MyDocumentsTestingmyFile.doc", ReadOnly:=True
With myWord
.Selection.GoTo What:=wdGoToBookmark, Name:="bkmTitle"
.Selection.typetext Text:=myCourse
End With

The document will open, but it says the bookmark does not exist. If I stop the macro, and go into the word document, the bookmark is definately there, and if I record a macro to go to it in word, it looks just like the line here, all I have added is a dot at the start because it's within a "With" routine.
Any help on why it's not working appreciated, but to win tonights star prize, you have to fix it.

Thanks dudes,
Phil.

ps. I am using office 97
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Mudface

MrExcel MVP
Joined
Feb 18, 2002
Messages
3,339
This seems to work OK (change the filename back to what it was in your own macro): -

Code:
Set myWord = CreateObject("Word.Application")
With myWord
    .Visible = True
    .Documents.Open Filename:="C:My DocumentsmyFile.doc", ReadOnly:=True
    .ActiveDocument.Bookmarks("bkmTitle").Select
    .Selection.typetext Text:=myCourse
End With
 

philR

Active Member
Joined
Feb 25, 2002
Messages
257
Works like a charm. Thanks Mudface, I have lost count of the number of imponderables you have solved for me!

Oh yes, your star prize is one of my favorite links,

http://www.iwantoneofthose.com/cgibin/priamlnk.cgi?MP=STATIC^GIN137&PAGE='things.htm'

Thanks again!
 

Forum statistics

Threads
1,144,734
Messages
5,725,983
Members
422,652
Latest member
Elnene1

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top