Results 1 to 4 of 4

Thread: Copying content of word documents **resolved**

  1. #1

    Thread Starter
    Hyperactive Member maxl's Avatar
    Join Date
    Jan 2002
    Location
    Montréal
    Posts
    384

    Copying content of word documents **resolved**

    Hi, I'm trying to copy the contents of a Word document and paste it into another. Does anybody knows how to do that with the Word Object library or any other way ?? Thanks
    Last edited by maxl; Sep 30th, 2003 at 04:06 PM.
    COBOL sa suce !!!

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Here is an example of Peets code adapted:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4. Dim objWord As Object 'instead of Word.Application
    5. Dim wd As Object  'instead of Word.Document
    6.  
    7. On Error GoTo Err_Handler
    8.  
    9.     If objWord Is Nothing Then
    10.         Set objWord = CreateObject("Word.Application")
    11.     Else
    12.         Set objWord = GetObject(, "Word.Application")
    13.     End If
    14.    
    15.     DoEvents
    16.    
    17.     'Open you first Document
    18.     Set wd = objWord.Documents.Open("c:\FirstDoc.doc")
    19.    
    20.     wd.ActiveWindow.Selection.WholeStory
    21.     wd.ActiveWindow.Selection.Copy
    22.    
    23.     'Open you second Document
    24.     Set wd = Nothing
    25.     Set wd = objWord.Documents.Open("c:\SecondDoc.doc")
    26.     wd.ActiveWindow.Selection.Paste
    27.    
    28.     objWord.Visible = True  'Show both Documents
    29.    
    30. Exit Sub
    31.  
    32. Err_Handler:
    33.     'quit word
    34.     If Not (wd Is Nothing) Then Set wd = Nothing
    35.     If Not (objWord Is Nothing) Then objWord.Application.Quit
    36.     If Not (objWord Is Nothing) Then Set objWord = Nothing
    37.    
    38.     MsgBox "Number: " & Err.Number & vbCrLf & _
    39.     "Description: " & Err.Description, vbOKOnly + vbCritical, "Error!"
    40. End Sub

  3. #3

    Thread Starter
    Hyperactive Member maxl's Avatar
    Join Date
    Jan 2002
    Location
    Montréal
    Posts
    384
    Thank you very much . But just wondering is there a difference if I declare directly as Word.Apliication and same for document ??
    COBOL sa suce !!!

  4. #4
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Originally posted by maxl
    Thank you very much . But just wondering is there a difference if I declare directly as Word.Apliication and same for document ??
    Probably so you don't need a Reference to MSWord Object Library.

    (If you use "Dim oWd as Word.Application", then you'll need the Lib reference).



    Bruce.

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