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 to Create a New Word Document from a Template in VBA 2

Status
Not open for further replies.

DeLara

Technical User
Jul 15, 2010
3
US
Hello, I have created a switchboard type form in Access2010, when I click on one of the buttons on the form I would like it to open a word template (.dot file) that I have created as a new word document (.doc). I run Windows XP and MS Office 2010. Below is what I have so far which I have gotten from various web sites. (I am VERY new to VB 7)

Private Sub Option1_Click()
Dim WordApp As Word.Application
Dim WordTemp As Word.Template
Dim STRTempName As String
STRTempName = "C:\Documents and Settings\delara\Desktop\Projects\Reports\Test\Templates\TheFile.dot"
Set WordApp = Word.Application
Set WordTemp = WordApp.Documents.Open(STRTempName)
WordApp.Visible = True
End Sub

the problem is that it opens up the actual .dot file in a read-only type setting.

Thank you in advance,
DeLara
 
I'd try this:
Code:
Private Sub Option1_Click()
Dim WordApp As Object
Dim STRTempName As String
STRTempName = "C:\Documents and Settings\delara\Desktop\Projects\Reports\Test\Templates\TheFile.dot"
Set WordApp = CreateObject("Word.Application")
WordApp.Documents.Add STRTempName
WordApp.Visible = True
End Sub

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank You so much PHV, I had been working on the this one problem forever. You have really helped me out of a bind at work. Just one more tiny question, the code works perfectly, but when I go to close the document, Word asks if I want to save the dot file and I would like it to just ask me where and what name to save it, I will need to save it as a doc file.

Thank you again your are an angel!!!
 
It should not be doing that. Are you executing any other code during this?

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top