Why don't I get this to work?
I have found this example that solves an immediate issue for me. That is if I get to work at least! What I need is a macro that merges 2 Word documents into 1.
WrdDoc1 + WrdDoc2 = WrdDoc3
Note! Code is in Excel and as this was originally intended for Word as comments show. I have altered the code some to try to get it to work but I get: "Run time error 438 - the object does not support the attribute or the method... (translated from Swedish)" at "Selection.TypeText Text:=paragraphText"
[VBA]
' Start Microsoft Word 2007. Select the "Developer" tab and click "Visual Basic." Right-click "Microsoft Word Objects," click "Insert" and select "Module."
' Type the following to create a new sub:
Sub MergeTwoDocs()
' Type the following to create variables used for storing data:
Dim wrdApp As Object
Dim wrdDoc As Word.Document
Dim paragraphText As String
Dim paragraphRange As Word.Range
Dim paragraphCount As Long
' Type the following to define your "wordApplication" variable:
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
' Type the following to open the "first" document to merge:
Set wrdDoc = wrdApp.Documents.Open("C:\Documents and Settings\...\629F36\1.docx")
' Type the following to call the "readDocument" sub and send the "first" document object as a parameter:
Call readDocument(wrdDoc)
' Type the following to open the "second" document to merge:
Set wrdDoc = wrdApp.Documents.Open("C:\Documents and Settings\...\629F36\2.docx")
' Type the following to call the "readDocument" sub and send the "second" document object as a parameter:
Call readDocument(wrdDoc)
End Sub
' Type the following to create the "readDocument" sub that will read any word document object passed in and add the contents to the current document:
Private Sub readDocument(wrdDoc As Object)
With wrdDoc
For paragraphCount = 1 To .Paragraphs.Count
Set paragraphRange = .Range(Start:=.Paragraphs(paragraphCount).Range.Start, _
End:=.Paragraphs(paragraphCount).Range.End)
paragraphText = paragraphRange.Text
Selection.TypeText Text:=paragraphText
Selection.TypeParagraph
Next paragraphCount
.Close
End With
End Sub
[/VBA]