'Excel VBA: Copy table to MS Word
I have created the following code to copy my table to word and its working well however the table is not formatted to fit in one window. Kindly help me with a line that will fit my table to window and put it in landscape format.
Sub Rectangle32_Click()
Dim wdApp As Object
Dim SaveName As String
Set wdApp = CreateObject("Word.Application")
With wdApp
'.Visible = True
'.Activate
.documents.Add
With .Selection
.ParagraphFormat.Alignment = 1
.BoldRun
.Font.Size = 16
.TypeText "PRIORITY AREA 1: WOMEN & GIRLS SOCIO-ECONOMIC EMPOWERMENT REPORT"
.BoldRun
.TypeParagraph
.Font.Size = 11
.ParagraphFormat.Alignment = 0
.TypeParagraph
End With
Range("I11:Q30", Range("I11:Q30").End(xlDown).End(xlToRight)).Copy
.Selection.Paste
With Selection
Application.CutCopyMode = False
End With
SaveName = Environ("UserProfile") & "C:\Users\Brighton M. Ilukena\OneDrive - ActionAid\Desktop\Thematic Reports" & _
Format(Now, "yyyy-mm-dd hh-mm-ss") & ".docx"
.ActiveDocument.Close
.Quit
End With
Set wdApp = Nothing
End Sub
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
