ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   multiple worksheets in workbook mail merged into a word documents (https://www.excelbanter.com/excel-worksheet-functions/153332-multiple-worksheets-workbook-mail-merged-into-word-documents.html)

La

multiple worksheets in workbook mail merged into a word documents
 
I'm not sure if this is possible since I'm new at this. Trying to print
labels, letters in word with the data source being a excel document with
multiple sheets contained in it with the information that I need. Is this
possible? Is it difficult to do?

Thanks.
Al

ryguy7272

multiple worksheets in workbook mail merged into a word documents
 
Try this sub:

Sub CopyWorksheetsToWord()
' requires a reference to the Word Object library:
' in the VBE select Tools, References and check the Microsoft Word X.X
object library
Dim wdApp As Word.Application, wdDoc As Word.Document, ws As Worksheet
Application.ScreenUpdating = False
Application.StatusBar = "Creating new document..."
Set wdApp = New Word.Application
Set wdDoc = wdApp.Documents.Add
For Each ws In ActiveWorkbook.Worksheets
Application.StatusBar = "Copying data from " & ws.Name & "..."
ws.UsedRange.Copy ' or edit to the range you want to copy
wdDoc.Paragraphs(wdDoc.Paragraphs.Count).Range.Ins ertParagraphAfter
wdDoc.Paragraphs(wdDoc.Paragraphs.Count).Range.Pas te
Application.CutCopyMode = False
wdDoc.Paragraphs(wdDoc.Paragraphs.Count).Range.Ins ertParagraphAfter
' insert page break after all worksheets except the last one
If Not ws.Name = Worksheets(Worksheets.Count).Name Then
With wdDoc.Paragraphs(wdDoc.Paragraphs.Count).Range
.InsertParagraphBefore
.Collapse Direction:=wdCollapseEnd
.InsertBreak Type:=wdPageBreak
End With
End If
Next ws
Set ws = Nothing
Application.StatusBar = "Cleaning up..."
' apply normal view
With wdApp.ActiveWindow
If .View.SplitSpecial = wdPaneNone Then
.ActivePane.View.Type = wdNormalView
Else
.View.Type = wdNormalView
End If
End With
Set wdDoc = Nothing
wdApp.Visible = True
Set wdApp = Nothing
Application.StatusBar = False
End Sub

Not sure who the author is, so I can't give credit even though it is due for
this...



Regards,
Ryan---

"la" wrote:

I'm not sure if this is possible since I'm new at this. Trying to print
labels, letters in word with the data source being a excel document with
multiple sheets contained in it with the information that I need. Is this
possible? Is it difficult to do?

Thanks.
Al



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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com