# VBA: change orientation to Landscape for word document converted from excel



## BKChedlia (Dec 12, 2017)

Dear all,

I have an excel file which I want to convert to word.

As the column number is big, the word document doesn't show all information, some of columns are not visible.

I changed manually the orientation to Landscape and I was able to see all data.

_*Issue VBA the change orientation to landscape not working.*_

This is my code:


```
Sub PasteToWord()     
    Dim wdApp As Object
    Dim wd As Object
     
    On Error Resume Next
    Set wdApp = GetObject(, "Word.Application")
    If Err.Number <> 0 Then
        Set wdApp = CreateObject("Word.Application")
    End If
    On Error GoTo 0
     
    Set wd = wdApp.Documents.Add
     
    wdApp.Visible = True
   Sheets("Sheet2").UsedRange.Font.Size = 8
Sheets("Sheet2").UsedRange.Copy
    wd.Range.Pasteandformat 0
   


wd.PageSetup.Orientation = wdOrientLandscape


wd.SaveAs ActiveWorkbook.Path & Application.PathSeparator & "Final_Report.docx"


    
End Sub
```

Can you please advice.
Thank you


----------



## Macropod (Dec 13, 2017)

You're referring to the orientation via wdOrientLandscape - which is a Word constant - but, unless you've set a reference to Word, the code won't know what to make of it. Since you're apparently using late binding (otherwise you wouldn't use 'Dim wdApp As Object') you need to either:
1. define wdOrientLandscape, like:
Const wdOrientLandscape as Long = 1
or 
2. supply the constant's value explicitly, like:
wd.PageSetup.Orientation = 1 'wdOrientLandscape


----------



## BKChedlia (Dec 13, 2017)

Thank you for help Macropod


----------

