visual basic and word

matthewbeetle
06-11-2001, 05:05 PM
does anybody know how to export data entered into a text box in visual basic to a textbox in a word document? any help would be appreciated!

mat

Yoda
06-12-2001, 01:37 AM
Lay a reference to Word in your VB app and open it using word. Then you can transfer the text in many ways, the easiest of which is to put a textbox on your word doc too, or insert a bookmark at a certain position and write the text to the bookmark.

<font color=green>Do or do not
There is no try</font color=green>

BlueRaja
06-12-2001, 03:24 AM
Is this really a question about how to pass a param from VB to word vba? If it is I would really like to know the answer. The best I can come up with is this sort of thing:

In your VB you have a form with a text box and a button:


Dim objWord As Word.Application

Private Sub Form_Load()
'create instance of word
Set objWord = New Word.Application
objWord.Visible = True
End Sub

Private Sub Command1_Click()
Dim objdoc As Word.Document
'open your doc with text box and transfer macro
objWord.Documents.Open FileName:="d:\vb\vb7\vbexamp.doc"


'Create a property
objWord.Documents("vbexamp.doc").CustomDocumentProperties.Add _
Name:="Param", LinkToContent:=False, Value:=" ", _
Type:=4

'set value of property
objWord.Documents("vbexamp.doc").CustomDocumentProperties("Param").Value = Text1.Text

'Run word macro
objWord.Application.Run MacroName:="Transfer"

'remove property
objWord.Documents("vbexamp.doc").CustomDocumentProperties("Param").Delete
End Sub


In your word document (vbexamp.doc) you have a text box and a macro:

Public Sub Transfer()
TextBox1.Text = ActiveDocument.CustomDocumentProperties("Param").Value
End Sub

Which works but is dull.


what I want to be able to do is something like:
objWord.Application.Run MacroName:="Transfer(" & text1.text & ")"

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum