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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
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
 
Upvote 0
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!
 
Upvote 0

Forum statistics

Threads
1,215,477
Messages
6,125,037
Members
449,205
Latest member
Eggy66

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
Back
Top