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

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,818
Members
449,049
Latest member
cybersurfer5000

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