Accessing a Text Box in a Word Document from Excel

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I copy a string from my exel document to a text box on a form in a
word document?

I can open the word document with the following:

Dim appWD As Word.Application
Set appWD = CreateObject("Word.Application")
appWD.Documents.Open Filename:=strPath & "\Letter.dot"

I just dont know how to refence the text box to then make it equal to the
string.

Thanks for your help in advance.
 
In excel first add reference to "Mocrosoft Word xx.x Object Library"
Add following code below the last line of your code and see.

'1. Referring by index number: First find out the inderx number of the text
box. if it is the only Shape in document it will be 1.
' Replace (n) below with the index number.

appWD.ActiveDocument.Shapes(n).TextFrame.TextRange.Text = "Was the reference
to text box success?"
appWD.ActiveDocument.SaveAs ("C:\letter1.doc")
appWD.ActiveDocument.Close
Exit sub

'2: Referring by name: First find out the name of the text box object -
which Typically will be "Text Box n".
'Replace n with the correct number.

appWD.ActiveDocument.Shapes("Text Box n").TextFrame.TextRange.Text = "Was
the reference to text box success?"
appWD.ActiveDocument.SaveAs ("C:\letter1.doc")
appWD.ActiveDocument.Close
Exit sub

Sharad
 

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

Back
Top