CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2004
    Posts
    100

    Word Automation in VB6

    Hey all
    Hope everyone is having a good holiday. I have a problem. I used the code below to help in automation of a word document. This code pulls a text field from multiple records and places them on this one document.

    Since this document now has all the information I need to retrieve, I want to copy what is on this one document and have it display on the other 4 documents that I need to open with automation without having to do a manual cut and paste. I want the application to handle it. Does anyone know what code I can use to do that with for the other documents?
    Thanks
    Kim

    Code:
     i = rs.RecordCount
    
        Do While i > 0
            objWD.activedocument.Bookmarks.Item("Actions").Range.Text = frmAircraftWO.rtxtActions & vbCrLf
            If i = 1 Then
                rs.MoveFirst
                MsgBox "You are at the beginning."
                Exit Do
            End If
            NextRecord
            i = i - 1
        Loop

  2. #2
    Join Date
    Dec 2002
    Location
    London, UK
    Posts
    1,569

    Re: Word Automation in VB6

    Well, at the moment you are using the .ActiveDocuemnt property to get the current doc. I would firstly store that in a variable. Secondly, get any other docs using the . Docuements property.
    Mike

  3. #3
    Join Date
    Jan 2004
    Posts
    100

    Re: Word Automation in VB6

    I am not understanding you when you say store that in a variable. I am not sure I know what or how to store it. Do you mean capture the contents of objWD.activedocument.Bookmarks.Item("Actions").Range.Text and assign it to a variable?

    I am not worried about the other documents, I have them already. I just want to see if I can copy what's on this document to the other's using the application.
    Thanks
    Kim

  4. #4
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    516

    Re: Word Automation in VB6

    I think Pinky98 had something like this in mind:
    Code:
        Dim oDoc As Word.Document
        
        i = rs.RecordCount
        
        Do While i > 0
            Set oDoc = objWD.ActiveDocument
            oDoc.Bookmarks.Item("Actions").Range.Text = frmAircraftWO.rtxtActions & vbCrLf
            '....
    Make an object variable for a document, and then assign the ActiveDocument reference to it. That way, you can make different documents active and still keep track of which document you are working on. After that, pretty much all you have to do is assign the other documents to objects, and then work on all of them at once. Something like:
    Code:
        Dim oDoc2 As Word.Document, oDoc3 As Word.Document, oDoc4 As Word.Document
        
        Set oDoc2 = objWD.Documents.Open("File1.doc")
        Set oDoc3 = objWD.Documents.Open("File2.doc")
        Set oDoc4 = objWD.Documents.Open("File3.doc")
        'Now you can work with all of the documents at once.
        oDoc2.Bookmarks.Item("Actions").Range.Text = oDoc.Bookmarks.Item("Actions").Range.Text
        'Etc.

  5. #5
    Join Date
    Jan 2004
    Posts
    100

    Re: Word Automation in VB6

    Oh, I see what you mean. I have done that already but I did it seperately for each document. I guess if I set all the documents together in one command than all of the text will be copied to each documenta at the same time. I think I have got it. Sometimes figuring out the layout of how your code should be is not easy, nor does it make sense at first. My thought at that point in time is to get it to work, not how to get it to work efficiently.
    Thanks Comintern.

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

Featured