input form output
RH

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Input form - output word doc

Input form - output word doc

resolvedResolved · Medium Priority · Version 2010

Vicki has attended:
Excel VBA Introduction course

Input form - output word doc

I have created a form in Excel and want to get it to populate a word template when clicking on a command button. I have tried starting with the code below, but it's telling me there is a runtime error and looks like the error is relating to the file path, which is correct, am I doing the code wrong? would it be easier to do this all in word for a word output document? thanks

Private Sub CommandButton1_Click()
Dim wapp As Word.Application
Dim wdoc As Word.document
Set wdoc = wapp.documents.Open("J:\smi-uk.ajgco.com\smidata\VOL1\Financial Risks\Ops\Vicki\SoDaN Template.dotx")
wapp.Visible = True
If Me.OptionButton1 = True Then
wdoc.Selection.typetext.Sheet2 Range("b2")
ElseIf Me.OptionButton2 = True Then
wdoc.Selection.typetext.Sheet2 Range("b3")
End If

RE: Input form - output word doc

Hi Vicki,

Thank you for the forum question.

I didn't spot that you missed a very important line in the code you sent me in the email.


You do not create an instance of the Word application object.

Set wapp = CreateObject("Word.Application")

The above line will do this. I have placed the line in the code below.





Set wapp = CreateObject("Word.Application")

Private Sub CommandButton1_Click()
Dim wapp As Word.Application
Dim wdoc As Word.document
Set wapp = CreateObject("Word.Application")

Set wdoc = wapp.documents.Open("J:\smi-uk.ajgco.com\smidata\VOL1\Financial Risks\Ops\Vicki\SoDaN Template.dotx")
wapp.Visible = True
If Me.OptionButton1 = True Then
wdoc.Selection.typetext.Sheet2 Range("b2")
ElseIf Me.OptionButton2 = True Then
wdoc.Selection.typetext.Sheet2 Range("b3")
End If
End Sub

Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Adding date and time

Here are two quick ways to add the date and time to your spreadsheet:

1) Type =NOW(), which displays both date and time in the same cell
or
2) Hold Ctrl and type the colon (:) into one cell for the date and the semi-colon(;)into another for the time.

Note that =NOW() updates to the current date/time whenever the spreadsheet recalculates.

View all Excel hints and tips


Server loaded in 0.05 secs.