VBA currently exports each tab into a separate word document. Need to update it to export each tab onto separate page in same Word doc!

aw12g10

New Member
Joined
Feb 26, 2015
Messages
2
Hi all,


Pretty much as the title states! I'm using a Macro I've had for a while to export certain data ranges into individual word documents. I need to develop this into the macro exporting each tab into a new page on the word document. The VBA I'm using is:


Code:
Option Explicit
 
Sub PasteToWord()
     
    Dim AppWord         As Word.Application
     
    Set AppWord = CreateObject("Word.Application")
    AppWord.Visible = True
     '  Change the range to suit your needs. See the How to Use for this code
    Sheets("UK Digital").Range("B1:Bk35").Copy
    AppWord.Documents.Add
    AppWord.Selection.Paste
     
    Application.CutCopyMode = False
     
    Set AppWord = Nothing
     
    Set AppWord = CreateObject("Word.Application")
    AppWord.Visible = True
     '  Change the range to suit your needs. See the How to Use for this code
    Sheets("Print").Range("B1:BK37").Copy
    AppWord.Documents.Add
    AppWord.Selection.Paste
     
    Application.CutCopyMode = False
     
    Set AppWord = Nothing
    
        Set AppWord = CreateObject("Word.Application")
    AppWord.Visible = True
     '  Change the range to suit your needs. See the How to Use for this code
    Sheets("International").Range("B1:BN24").Copy
    AppWord.Documents.Add
    AppWord.Selection.Paste
     
    Application.CutCopyMode = False
     
    Set AppWord = Nothing
End Sub


As you can see, I'm creating a new document for each tab; "UK Digital, Print, International" etc. Please can you help me with getting these into the same document on individual pages?


Thanks


Alex
 
Last edited by a moderator:

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Try:
Code:
Sub PasteToWord()
    Dim AppWord As New Word.Application
    With AppWord
      .Documents.Add
      With .ActiveDocument.Range
        Sheets("UK Digital").Range("B1:BK35").Copy
        .Characters.Last.Paste
        .InsertAfter Chr(12)
        Sheets("Print").Range("B1:BK37").Copy
        .Characters.Last.Paste
        .InsertAfter Chr(12)
        Sheets("International").Range("B1:BN24").Copy
        .Characters.Last.Paste
      End With
    AppWord.Visible = True
    End With
    Set AppWord = Nothing
    Application.CutCopyMode = False
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,790
Messages
6,174,600
Members
452,574
Latest member
hang_and_bang

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top