|
-
Sep 29th, 2003, 04:58 PM
#1
Thread Starter
Hyperactive Member
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 !!!
-
Sep 29th, 2003, 05:58 PM
#2
Here is an example of Peets code adapted:
VB Code:
Option Explicit
Private Sub Command1_Click()
Dim objWord As Object 'instead of Word.Application
Dim wd As Object 'instead of Word.Document
On Error GoTo Err_Handler
If objWord Is Nothing Then
Set objWord = CreateObject("Word.Application")
Else
Set objWord = GetObject(, "Word.Application")
End If
DoEvents
'Open you first Document
Set wd = objWord.Documents.Open("c:\FirstDoc.doc")
wd.ActiveWindow.Selection.WholeStory
wd.ActiveWindow.Selection.Copy
'Open you second Document
Set wd = Nothing
Set wd = objWord.Documents.Open("c:\SecondDoc.doc")
wd.ActiveWindow.Selection.Paste
objWord.Visible = True 'Show both Documents
Exit Sub
Err_Handler:
'quit word
If Not (wd Is Nothing) Then Set wd = Nothing
If Not (objWord Is Nothing) Then objWord.Application.Quit
If Not (objWord Is Nothing) Then Set objWord = Nothing
MsgBox "Number: " & Err.Number & vbCrLf & _
"Description: " & Err.Description, vbOKOnly + vbCritical, "Error!"
End Sub
-
Sep 29th, 2003, 10:04 PM
#3
Thread Starter
Hyperactive Member
Thank you very much . But just wondering is there a difference if I declare directly as Word.Apliication and same for document ??
-
Sep 30th, 2003, 04:47 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|