Results 1 to 2 of 2

Thread: Writing to MS Word

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Posts
    19

    Writing to MS Word

    I have made a Word Template with Bookmarks and an application that writes to the bookmarks with data from the app. I have Word 2003 installed on my system. After creating the setup and installing it on another system the App crashed, I then noticed the other system has XP installed. So here is my question, is there a way to create an app that write data to bookmarks within Word that is independant of the version of Word being using? I will need to it work on systems with Word 2000, XP or 2003 installed.

    I tried some test code, trying to make it work but was not successful, only works with the version of Word installed on my system. Here is the test code I used...

    Dim WordApp As New Word.Application
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim ReportGenerator As New Word.Document
    ReportGenerator = WordApp.Documents.Open("C:\Report Generator\Demo.doc")
    With ReportGenerator


    If Len(txtName1.Text) > 0 Then
    .Bookmarks("Name1").Select()
    WordApp.Selection.TypeText(txtName1.Text)
    End If

    If Len(txtName2.Text) > 0 Then
    .Bookmarks("Name2").Select()
    WordApp.Selection.TypeText(txtName2.Text)
    End If



    .Close(Word.WdSaveOptions.wdSaveChanges)
    End With
    WordApp.Quit()

    Thanks

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367
    Try using Late Binding instead of creating a reference to the Word Object.

    so

    VB Code:
    1. Dim WordApp As New Word.Application

    would become
    VB Code:
    1. Dim WordApp as Object
    2. WordApp = CreateObject("Word.Application")

Posting Permissions

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



Click Here to Expand Forum to Full Width