• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Exporting entire Excel Worksheets to Word with original formatting

roger100

New Member
Hello,

I've been trying to figure this out for a while now, but just can't seem to figure it out.
The goal is to simply extract excel sheets into word keeping the same format as it is in the excel sheets, including the header (which is an image), and a footer.

With my current code, the information is copied but completely misaligned and the page breaks are also not correct. Moreover, although I am using the UsedRange function, the header and footer are not being copied over to Word.

Any help would be much appreciated! Please find attached an example excel sheet and also the current word document result I am getting now.

Thank you so much in advance!

Code:
Option Explicit

Sub CreateBasicWordReport()

Dim wdApp As Word.Application
Set wdApp = New Word.Application
Dim tbl As Excel.Range
Dim SrcePath As String

With wdApp
.Visible = True
.Activate

.Documents.Add

  
End With

Set tbl = ThisWorkbook.Worksheets(Sheet1.Name).UsedRange
tbl.Copy


wdApp.Selection.Paste

End Sub

Sub CreateBasicWordReportAutoInstancing()
Dim wdApp As New Word.Application

If wdApp Is Nothing Then
MsgBox "Word doesn't exist"
End If

wdApp.Visible = True
wdApp.Activate

End Sub
 

Attachments

  • Example_excel.xlsm
    121 KB · Views: 1
  • Example_Word_Result.docx
    23.6 KB · Views: 0
Back
Top