Logo
English Russian German French Spanish Italian
contact usprivacy
   Support Forums
chart
• Adjust flexgrid cell
• Animation
• Centering form text
• Coffee machine
• Creating fileshares
• Creating shortcuts
• Custom buttons
• Directory browser
• Disable mouse events
• File search by ext
• File transfer
• File watcher
• Formatting flexgrid
• Get Content Type
• Get HTML source
• Get modem port
• HTTP proxy
• ipconfig
• Large file split/merge
• MAPI
• MCI Sound Player
• Menu with images
• MP3 normalizer
• Net Send
• Netstat 2000
• No duplicate entries
• Outlook Address Book
• Set font color
• Shapes
• SOAP test
• Text-to-image
• Text file viewer
• Text find/replace
• UPS component
• View NT groups
• Word template
• Writing DNS control
    • Using DNS control
• Writing SMTP control
    • Sending email
    • Mailing list
• Writing WhoIs control
    • Using WhoIs control
• View HTML source
OISV - Organization of Independent Software Vendors - Contributing Member
VB projects - Using Word template

Description: Writing the program that open selected text file, apply Word template to it and print out the resulting document
Minimum requirements: vb5, MS Word 7.0
Download: source code
Screenshot:
template (3017 bytes)
Project: Standard EXE
Controls: txtFile (textbox), txtTemplate (textbox), cmdFile (button), cmdTemplate (button), cmdRun (button), dlg (common dialog control)
Additional project references: Microsoft Word Object Library
Code:
Private Sub cmdFile_Click()
    dlg.FileName = "*.txt"
    dlg.ShowOpen
    txtFile = dlg.FileName
End Sub

Private Sub cmdTemplate_Click()
    dlg.FileName = "*.dot"
    dlg.ShowOpen
    txtTemplate = dlg.FileName
End Sub

Private Sub cmdRun_Click()
    Dim wa As Word.Application
    Dim wt As Word.template
    Dim strTemp As String
    Dim strOutput As String

    Set wa = New Word.Application
    wa.AddIns.Add txtTemplate, True
    Set wt = wa.Templates(txtTemplate)
    wa.Documents.Add wt.FullName, newtemplate:=False
    Open txtFile For Input As 1
    While Not EOF(1)
        Line Input #1, strTemp
        strOutput = strOutput & strTemp & vbCrLf
    Wend
    Close #1
    Clipboard.Clear
    Clipboard.SetText (strOutput)
    wa.Selection.WholeStory
    wa.Selection.Paste
    wa.ActiveDocument.PrintOut
    While wa.BackgroundPrintingStatus > 0
        DoEvents
    Wend
    Set wt = Nothing
    wa.Quit (wdDoNotSaveChanges)
    Set wa = Nothing
End Sub

Copyright © 1996-2010 OstroSoft. All rights reserved. info@ostrosoft.com