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

open a word document using a template

Status
Not open for further replies.

basbrian

Programmer
Feb 18, 2002
49
0
0
AU
I am trying to create and save a .doc file by using a .dot, but my code is saving the insert of the bookmark into both documents. how do I close the .dot file without saving any changes? please ignore the roughness of this code as I am just learning vb and I am trying to see if I can get the basics to work.
Code:
 Private Sub Print_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Print_Button.Click
        MsgBox(CboName.Text)


        Dim appWord As Word.Application = CreateObject("Word.Application")
        Dim docWord As Word.Document
        Dim opara1 As Word.Paragraph

        docWord = appWord.Documents.Open("q:\computer.adm\basbrian\delegation.dot")
        'appWord.Documents.Add()
        appWord.Visible = True

        opara1 = docWord.Content.Paragraphs.Add(docWord.Bookmarks.Item("gm").Range)
        opara1.Range.Text = "Stephen Sawtell"
        oPara1.Format.SpaceAfter = 6
        oPara1.Range.InsertParagraphAfter()

        docWord.SaveAs("q:\computer.adm\basbrian\sdb.doc", True)
        docWord.Close()
        docWord = Nothing
        appWord.Application.Quit()
        appWord = Nothing

    End Sub
End Class
 
Hi Basbrian,

To open a word template you can use.

Change this
Code:
docWord = appWord.Documents.Open("q:\computer.adm\basbrian\delegation.dot")

to this
Code:
docWord = appword.Documents.Add(Template:="q:\computer.adm\basbrian\delegation.dot", newtemplate:=False, Documenttype:=0)

Don't have the time to test it.
I usaly use appword.activedocument to fill the document.

Greetings,
Ernst Jan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top