Adding text at specific point

  • Thread starter David C. Holley
  • Start date
D

David C. Holley

Is it possible to add text at a specific location in a Word Doc via
code? If yes, how?
 
H

Helmut Weber

Hi David,

somewhat simplified:

ActiveDocument.Range.Characters(45).InsertAfter "xxx"


Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
D

David C. Holley

OK, well I've answered my own question, but the following line doesn't
work, although its somewhat directly from Word Help. Word is returning
'Object doesn't support this property or method'

[If .Bookmarks("BodyText").Exists = True Then]

The context of the line is below...

....
Set appWord = CreateObject("Word.Application")
appWord.Visible = True

varFullFileName = "C:\Documents and Settings\dch3\Desktop\invoice.doc"
appWord.Documents.Open FileName:=varFullFileName
Set targetDocument = appWord.Documents("invoice.doc")
With targetDocument
.FormFields("AccountInformation").Result = getAccountNameForWord(9)
.FormFields("InvoiceNo").Result = 90
.FormFields("InvoiceTotal").Result = 100
.FormFields("InvoiceBalance").Result = 200
.FormFields("Description").Result = "Invoice Description Here " & Now()
If .Bookmarks("BodyText").Exists = True Then
.Bookmarks("BodyText").Select
End If
....
 
D

Doug Robbins

The correct syntax is:

If .Bookmarks.Exists("BodyText") = True Then
.Bookmarks("BodyText").Select
End If


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
David C. Holley said:
OK, well I've answered my own question, but the following line doesn't
work, although its somewhat directly from Word Help. Word is returning
'Object doesn't support this property or method'

[If .Bookmarks("BodyText").Exists = True Then]

The context of the line is below...

...
Set appWord = CreateObject("Word.Application")
appWord.Visible = True

varFullFileName = "C:\Documents and Settings\dch3\Desktop\invoice.doc"
appWord.Documents.Open FileName:=varFullFileName
Set targetDocument = appWord.Documents("invoice.doc")
With targetDocument
.FormFields("AccountInformation").Result = getAccountNameForWord(9)
.FormFields("InvoiceNo").Result = 90
.FormFields("InvoiceTotal").Result = 100
.FormFields("InvoiceBalance").Result = 200
.FormFields("Description").Result = "Invoice Description Here " & Now()
If .Bookmarks("BodyText").Exists = True Then
.Bookmarks("BodyText").Select
End If
...
Is it possible to add text at a specific location in a Word Doc via code?
If yes, how?
 
D

David C. Holley

But of course, how stupid of me to expect that the Help file would be
correct.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top