Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2006
    Thanked 0 Times in 0 Posts

    Can you insert a file into a template? (Word 2000)

    I am very, very new to Word and VBA and I have created a letterhead template. There are 3 areas in the template where I want to put the user's phone number, email address and job title. I thought I could use bookmarks for these fields on the form and then create a macro that would insert a file at the bookmark point. The inserted file would be a little .txt file that would be picked up from a folder on the c drive, but I don't have a clue how to make this work or even if it is the best way to do this. If you have an idea of what I am talking about, please help a newbie. I am open to all suggestions. Thanks.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Thanked 31 Times in 31 Posts

    Re: Can you insert a file into a template? (Word 2000)

    Welcome to Woody's Lounge!

    You could use the old .ini file format - it still works well.

    I have attached a zip file with a Word document and an .ini file. If you want to test it, unzip both files to your default document folder for Word, then open the document and run the InsertData macro.

    The ini file looks like this:

    Phone=(123) 456-7890
    JobTitle=Bean counter

    The macro reads information from this file:

    Sub InsertData()
    ' Declare variables
    Dim strFile As String
    Dim strPhone As String
    Dim strEmail As String
    Dim strJobTitle As String

    ' We use the default document path here; modify as needed
    strFile = Options.DefaultFilePath(wdDocumentsPath) & "Data.ini"
    ' Retrieve some values
    strPhone = System.PrivateProfileString(strFile, "Info", "Phone")
    strEmail = System.PrivateProfileString(strFile, "Info", "Email")
    strJobTitle = System.PrivateProfileString(strFile, "Info", "JobTitle")

    ' Insert text at one bookmark.
    ActiveDocument.Bookmarks("Test1").Range.Text = _
    "Phone: " & strPhone & vbCr & _
    "E-mail: " & strEmail & vbCr & _
    "Job Title: " & strJobTitle
    ' Insert slightly different text at another bookmark
    ActiveDocument.Bookmarks("Test2").Range.Text = _
    "Phone: " & strPhone & ", " & _
    "E-mail: " & strEmail
    End Sub

    Note: make sure that macro security is not set to High, for that would disable the macro. Medium is the recommended setting.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts