Export Excel print pages to Word document

lumiere

New Member
Joined
Jan 13, 2021
Messages
4
Office Version
  1. 365
Platform
  1. Windows
I have an Excel file that contains only one Worksheet but it split into multiple pages with vertical page breaks (see attached image)

What's the best way to export that worksheet to Word document? So each Excel print page is a page in a Word document.
Is there a VBA script anyone can share?

Thanks in advance



Screenshot 2021-01-14 173102.png
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Bump.

So I guess this consists of two tasks
1. Loop through "Print pages" and establish cell ranges for each page
2. Each page's cell range should then be exported as table on a separate page in word document.

Does this sound like a correct way of approaching this?

I can't seem to find a way to do point 1 on my list. Can't find the way to iterate over print pages and get cell ranges. Is it even possible?
 
Upvote 0
VBA Code:
Sub Export_Excel_print_pages_to_Word_document()

Dim wrdApp As Object
Dim WrdDoc As Object
Dim Pages As Variant

Set wrdApp = CreateObject("Word.Application")

Path = Environ("USERPROFILE") & "\" & "Desktop\"
WrdPath = Path & "wrd.docx"
With wrdApp
    .Visible = True
    .Activate
     Set WrdDoc = .Documents.Add
   
             With WrdDoc
                Pages = Split(ActiveSheet.PageSetup.PrintArea, ",")
               ' MsgBox " You have " & UBound(Pages) + 1
                For P = LBound(Pages) To UBound(Pages)
                .Content.InsertAfter "Page (" & P + 1 & ")"
                ' Add Spaces
                .Paragraphs.Add
                .Paragraphs.Add

                ' Copy Excel
                Range(Pages(P)).Copy

                  'Paste
                .Paragraphs(.Paragraphs.Count).Range.Paste
               ' Add Spaces
                .Paragraphs.Add
                .Paragraphs.Add
                .Paragraphs.Add
                .Paragraphs.Add
                .Paragraphs.Add
                .Paragraphs.Add
                .Paragraphs.Add
                Next
               
               
            End With 'WrdDoc
           
End With 'wrdApp
Application.CutCopyMode = False

Set wrdApp = WrdDoc
Set wrdApp = Nothing

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,632
Messages
6,120,655
Members
448,975
Latest member
sweeberry

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