ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Accessing a Text Box in a Word Document from Excel (https://www.excelbanter.com/excel-programming/316554-accessing-text-box-word-document-excel.html)

Ben

Accessing a Text Box in a Word Document from Excel
 
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.

Sharad Naik

Accessing a Text Box in a Word Document from Excel
 
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


"Ben" wrote in message
...
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.





All times are GMT +1. The time now is 02:48 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com