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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you open a word template from excel and add selected

Status
Not open for further replies.

Matrrix

Programmer
Nov 6, 2002
8
CA
I've finally decided to ask for some assistance. I've had some progress but would like some help.

I would like to open "c:\work\contract.dot" from excel and insert excel data into the fields in the word document.

I've created a complex formula database in excel and a userform to access the info. I would like to create a button in excel that will open up a word document and insert the neccesary information.

Can anyone help?
 
It would help if you'd describe your efforts so far, and where you're getting stuck.
Cheers
Rob
 
I have the following subroutine developed. I need this routine to 1. Open up a specific template as a new document(c:\work\contracttemp.dot)Then I would like to send information from excel to the opened document.


Sub Open_MSWord()
On Error GoTo errorHandler
Dim wdApp As Word.Application
Dim myDoc As Word.Document
Dim mywdRange As Word.Range
Set wdApp = New Word.Application
With wdApp
.Visible = True
.WindowState = wdWindowStateMaximize
End With
Set myDoc = wdApp.Documents.Add
Set mywdRange = myDoc.Words(1)
With mywdRange
.Text = Range("F6") & " This text is being used to test subroutine." & _
" More meaningful text to follow."
.Font.Name = "Comic Sans MS"
.Font.Size = 12
.Font.ColorIndex = wdGreen
.Bold = True
End With
errorHandler:
Set wdApp = Nothing
Set myDoc = Nothing
Set mywdRange = Nothing
End Sub

Thanks Matrrix
 
If you put the templatename in as below, it will create a new document based on the template.

Set myDoc = wdApp.Documents.Add(templatename)

As far as entering information from Excel to word, I usually create named bookmarks in the word document where I need to insert information:

Word.ActiveDocument.FormFields.Item(bookmarkname).Result:= excelvalues
Leslie
landrews@metrocourt.state.nm.us

SELECT * FROM USERS WHERE CLUE > 0
No Rows Returned
 
Thanks for the assistance. Almost got it now.

Okay I now have it opening up my template, but I'm having difficulty having it enter the information I need into predetermined fields via bookmarks.

Can anyone help.

Matrrix

Sub Open_MSWord()
On Error GoTo errorHandler
Dim wdApp As Word.Application
Dim myDoc As Word.Document
Dim mywdRange As Word.Range
Set wdApp = New Word.Application
With wdApp
.Visible = True
.WindowState = wdWindowStateMaximize
End With
Set myDoc = wdApp.Documents.Add("c:\work\contracttemp.dot")
Word.ActiveDocument.FormFields.Item(Text7).Result = Client!A9
Set mywdRange = myDoc.Words(1)
With mywdRange
.Text = Range("F6") & " This text is being used to test subroutine." & _
" More meaningful text to follow."
.Font.Name = "Comic Sans MS"
.Font.Size = 12
.Font.ColorIndex = wdGreen
.Bold = True
End With
errorHandler:
Set wdApp = Nothing
Set myDoc = Nothing
Set mywdRange = Nothing
End Sub
 
Where the Word is in the following example:

Word.ActiveDocument.FormFields.Item(Text7).Result = Client!A9

You need to change to wdApp.ActiveDocument.etc...

That should take care of it!

Good Luck

la

Leslie
landrews@metrocourt.state.nm.us

SELECT * FROM USERS WHERE CLUE > 0
No Rows Returned
 
Still doesn't seem to be working. Not sure if this will help but the test text I have after the value doesnt work with fieldforms.text inserted. You mentioned you've done this before. Do you still have a working form of this code?

I would really appreciate it.

Again thanks for your assistance.

Matrix
 
I made a new one that works.

Thanks for your assistance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top