Update Word document

texasalynn

Well-known Member
Joined
May 19, 2002
Messages
8,458
I have this code but it is not working. It says that it can't find the bookmark, yet I have the bookmark on the Word document. I've looked at this but am not seeing why it doesn't work?
Code:
Private Sub SendPI_Form()
Application.ScreenUpdating = False
Application.DisplayAlerts = False

Dim MyWord As Object

'On Error GoTo Fixit
Set MyWord = CreateObject("Word.Application")
MyWord.ChangeFileOpenDirectory "S:\REPORTING ANALYSIS\Reporting Tools\Macros"
MyWord.Documents.Open Filename:="Temp Open Tops.doc"
MyWord.Visible = True

With MyWord.Selection

'Insert text into word document by user at bookmark (placeholders) locations
.Goto What:=wdGoToBookmark, Name:=RequestedBy
.TypeText Range("RequestedBy").Value

.Goto What:=wdGoToBookmark, Name:=Date
.TypeText Range("Date").Value

....more stuff 
End Sub

Thanks for taking a look
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Damon Ostrander

MrExcel MVP
Joined
Feb 17, 2002
Messages
4,239
Hi tex,

I don't see where you have declared RequestedBy as a variable or set its value. If RequestedBy is the name of the bookmark rather than a string variable containing the name, it should be enclosed in quotes. If it is a variable there should be a

Dim RequestedBy As String

.
.
.

RequestedBy = "mybookmarkname"

Damon
 

texasalynn

Well-known Member
Joined
May 19, 2002
Messages
8,458
I swear I had tried that and it didn't work either, but today it is. Thanks for the help.

One more thing, I have a date bookmark, but get a type mismatch. Not seeing why
 

Damon Ostrander

MrExcel MVP
Joined
Feb 17, 2002
Messages
4,239
Hi again tex,

I can't be sure without knowing what line of code is producing the error, but it looks to me like

.Goto What:=wdGoToBookmark, Name:=Date

is the offending line because the Excel Date function does not give a text string like Goto is expecting, but rather a number--which gets formatted as a text string date when printed. The problem should be cured by forcing the date to be converted to a text string:

.Goto What:=wdGoToBookmark, Name:=CStr(Date)

In addition, I recommend that you change

.TypeText Range("Date").Value

to

.TypeText Range("Date").Text

to ensure that the text entered is the text string date rather than the numerical date (i.e., days elapsed since 1900).

Keep Excelling.

Damon
 

Forum statistics

Threads
1,136,952
Messages
5,678,745
Members
419,782
Latest member
gc75150

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