Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default merge word documents from excel macro

Hello,

I want to create a marcro in excel that allows me to merge different word
documents.
Can anyone point me in the wright direction?

Thanks

Lieven

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default merge word documents from excel macro

Hi, try the below macro and feedback

--You can specify the files (with path) in the variable strFiles . In the
below example I have given 3 files with their full path (comma separated)

--Edit Save As file/path . In the below example it is given as
"c:\merge1.doc". Either assign this to a variable or edit for testing.

Sub MergeWordDocs()

Dim wrdApp As Word.Application, strFile As String
Dim wrdDoc As Word.Document, wrdNew As Word.Document

Set wrdApp = CreateObject("Word.Application")
Set wrdNew = wrdApp.Documents.Add

strFiles = "c:\1.doc,c:\2.doc,c:\Quick Response SLA.doc"

For intTemp = 0 To UBound(Split(strFiles, ","))
Set wrdDoc = wrdApp.Documents.Open(Split(strFiles, _
",")(intTemp), ReadOnly:=True)
wrdDoc.Range.Copy
Set myRange = wrdNew.Range(wrdNew.Content.End - 1, _
wrdNew.Content.End - 1)
myRange.Paste
wrdDoc.Close False: Set wrdDoc = Nothing
Next

wrdNew.SaveAs "c:\merge1.doc": wrdNew.Close True
wrdApp.Quit: Set wrdApp = Nothing
End Sub


If this post helps click Yes
---------------
Jacob Skaria


"lieven" wrote:

Hello,

I want to create a marcro in excel that allows me to merge different word
documents.
Can anyone point me in the wright direction?

Thanks

Lieven

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default merge word documents from excel macro

Forgot to mention that the previous post works only if you refer 'Microsoft
Word xx.0 Object Library' from VBEToolsReferences.

OR othewise use the below version...which creates the object at runtime..

Sub MergeWordDocs()

Dim wrdApp As Object, strFile As String
Dim wrdDoc As Object, wrdNew As Object
Set wrdApp = CreateObject("Word.Application")
Set wrdNew = wrdApp.Documents.Add

strFiles = "c:\1.doc,c:\2.doc,c:\Quick Response SLA.doc"

For intTemp = 0 To UBound(Split(strFiles, ","))
Set wrdDoc = wrdApp.Documents.Open(Split(strFiles, _
",")(intTemp), ReadOnly:=True)
wrdDoc.Range.Copy
Set myRange = wrdNew.Range(wrdNew.Content.End - 1, _
wrdNew.Content.End - 1)
myRange.Paste
wrdDoc.Close False: Set wrdDoc = Nothing
Next

wrdNew.SaveAs "c:\merge1.doc": wrdNew.Close True
wrdApp.Quit: Set wrdApp = Nothing

End Sub


If this post helps click Yes
---------------
Jacob Skaria


"Jacob Skaria" wrote:

Hi, try the below macro and feedback

--You can specify the files (with path) in the variable strFiles . In the
below example I have given 3 files with their full path (comma separated)

--Edit Save As file/path . In the below example it is given as
"c:\merge1.doc". Either assign this to a variable or edit for testing.

Sub MergeWordDocs()

Dim wrdApp As Word.Application, strFile As String
Dim wrdDoc As Word.Document, wrdNew As Word.Document

Set wrdApp = CreateObject("Word.Application")
Set wrdNew = wrdApp.Documents.Add

strFiles = "c:\1.doc,c:\2.doc,c:\Quick Response SLA.doc"

For intTemp = 0 To UBound(Split(strFiles, ","))
Set wrdDoc = wrdApp.Documents.Open(Split(strFiles, _
",")(intTemp), ReadOnly:=True)
wrdDoc.Range.Copy
Set myRange = wrdNew.Range(wrdNew.Content.End - 1, _
wrdNew.Content.End - 1)
myRange.Paste
wrdDoc.Close False: Set wrdDoc = Nothing
Next

wrdNew.SaveAs "c:\merge1.doc": wrdNew.Close True
wrdApp.Quit: Set wrdApp = Nothing
End Sub


If this post helps click Yes
---------------
Jacob Skaria


"lieven" wrote:

Hello,

I want to create a marcro in excel that allows me to merge different word
documents.
Can anyone point me in the wright direction?

Thanks

Lieven

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Excel Macro to Print Word Documents Mike[_109_] Excel Programming 2 July 24th 06 06:30 PM
How to merge excel and word documents jacqueline Excel Discussion (Misc queries) 1 March 28th 06 01:52 AM
can I merge documents in excel like I can in Word kaykayIT Excel Discussion (Misc queries) 3 November 10th 05 01:57 AM
how do I use mail merge in excel for word documents Lisa J Duffy Excel Discussion (Misc queries) 1 August 4th 05 01:40 PM
Creating Word Documents with an Excel Macro The Wonder Thing[_2_] Excel Programming 1 June 19th 04 12:15 AM


All times are GMT +1. The time now is 04:56 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"