Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add text to Word doc using vbscript

Status
Not open for further replies.

ktwclark

Programmer
Jan 30, 2002
54
GB
I'm having a problem finding the correct syntax for automating word through vbscript. I've managed to open the file but can't discover how to write to it. Any help would be appreciated. Any place I can find these syntaxes?

Cheers
 
how about recording a macro in Word itself and adding some text to a word document. You can then look at the VB code with the Visual Basic Editor that is built into word.

I used this method to figure out the code for automating word and opening a document. Tony
 
Have already tried this. I get this code in the macro that's produced

Selection.TypeText Text:="Test string"

but when I apply it the my HTML code I get an error. This is the code so far:

<SCRIPT language=VBScript>
<!--
Option Explicit

Sub cmdButton_OnClick()
Dim Word
Set Word = CreateObject(&quot;Word.Application&quot;)
Word.Visible = TRUE
Word.Documents.open (&quot;Q:/TestFile.dot&quot;)
End Sub
-->
</SCRIPT>

Q is the drive letter of my web site. I use the actual URL but have replaced for this example.
 
ktwclark,

try this...


Set appWord = CreateObject(&quot;Word.Application&quot;)
appWord.Visible = TRUE
' Open a sample document.
appWord.Documents.Add
appWord.Documents.Open(&quot;C:\doc1.doc&quot;)
appword.Selection.TypeText &quot;Test string&quot;


fengshui_1998
 
Thanks for the help. I actually needed to append character to the 2nd word, a #, of the document using a the contents of a asp variable. Pretty much the same code as above except for

Wordapp.ActiveDocument.Words(2).Text = &quot;#&quot; & <%=contents%>

which replaces # with # and the contents of the asp variable

Thanks for the help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top