Excel to Word report problem

R

rharrison

I want to be able to open up a word document when a User Form opens in Excel.

Once the word document is open, I want to add information to it, depending
on criteria met whilst the user is using the form.

So far I have been able to the Word report to open, but I'm not able to add
further details to it when buttons are clicked in the user form. I'm sure
this is straightforward, but I am struggling to see where I would be going
wrong. Can anyone help?

Thanks.
 
R

rharrison

When the page loads, I have...

Set wordApp = CreateObject("Word.Application")

With wordApp
.Visible = True
.Activate
End With

Set doc = wordApp.Documents.Add

Then, when the individual clicks the button it has...

With wordApp.Selection

..typetext "Test"

etc.

End With

Obviously, it's not picking up the wordApp tag. But I'm not sure how to
reference the application I've opened. Any help would be greatly appreciated.

Many thanks.
 
P

Patrick Molloy

I'm not sure if this example is what you need, but I have a command button
on the form, btnWrite, which has the following code:

Option Explicit
Private Sub btnWrite_Click()
Dim wordApp As Object
Dim doc As Object

With CreateObject("Word.Application")
.Visible = True
.Activate
Set doc = .Documents.Add
.Selection.typetext txtName.Text & vbCrLf
.Selection.typetext txtAddress1.Text & vbCrLf
.Selection.typetext txtAddress2.Text
End With
Unload Me
End Sub

this writes the contents of three text boxes to the document
 

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