CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: VBA

  1. #1
    Join Date
    Mar 2001
    Posts
    4

    VBA

    When I merge documents in MSWord-97 that contain comments (annotations), some of the merged comments may become mixed (scrambled) with other comments.

    kindly suggest the solution to merge the documents perfectly or suggest any alternate way to accomplish the task.




  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: VBA

    Try this code

    ' Don't forget to add the "Microsoft Word 8.0 Object Library"

    private Sub cmdButton_Click()
    Dim objWord as Word.Application 'you can also declare it "as Object"

    On error GoTo errorhandler

    ' create the word object (following code is VBA)
    set objWord = CreateObject("Word.Application")
    objWord.Visible = true 'not required

    ' merge the two files to one
    objWord.Documents.Open FileName:="C:\FIRST.DOC"
    objWord.Selection.EndKey Unit:=wdStory
    objWord.Selection.InsertFile FileName:="C:\SECOND.DOC"

    ' save, close and exit
    objWord.ActiveDocument.SaveAs "C:\BOTH.DOC"
    objWord.ActiveDocument.Close
    objWord.Quit
    set objWord = nothing

    'free the object
    MsgBox "I am ready"

    Exit Sub

    errorhandler:
    MsgBox Err.Number & vbCrLf & Err.Description
    End Sub







    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

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