VBA Code to change orientation to Landscape help

Daniellel

Board Regular
Joined
Jun 21, 2011
Messages
242
Hi, i have an excel doc that currently has some code to copy a selection and paste it into a word document... I set it all up on a windows machine but now need to use it on a apple mac and what a surprise, it doesn't work! after hours of googling and amending my code to work with apple i am almost there... the only thing i cant seem to find online is how to make the word document Landscape... this is the code i have for windows and what i have for mac... it doesn't like the orientation of the margin sizes. Can anyone help?
Windows Code:
VBA Code:
Dim objPrintWord, objPrintDoc As Object
    Set objPrintWord = CreateObject("Word.Application")
    Set objPrintDoc = objPrintWord.Documents.Add
        With objPrintDoc.PageSetup
        .Orientation = wdOrientLandscape
        .TopMargin = CentimetersToPoints(1)
        .BottomMargin = CentimetersToPoints(1)
        .LeftMargin = CentimetersToPoints(1)
        .RightMargin = CentimetersToPoints(1)
End With

Mac Code:
VBA Code:
Dim oWord As Object
Application.Wait (3)
Set oWord = CreateObject(Class:=("Word.application"))
oWord.Visible = True
oWord.Activate
Dim oDoc
Set oDoc = oWord.Documents.Add

With oDoc.PageSetup
    .Orientation = wdOrientLandscape
    .TopMargin = CentimetersToPoints(1)
    .BottomMargin = CentimetersToPoints(1)
    .LeftMargin = CentimetersToPoints(1)
    .RightMargin = CentimetersToPoints(1)
End With
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
What does "doesn't like" mean?

It looks like your code is late bound, so wdOrientLandscape has no value. Try declaring it yourself:

Code:
Const wdOrientLandscape as long = 1

and see if that helps. You also might as well just work out the value of CentimetersToPoints(1) and put that in the code.
 
Upvote 0
What does "doesn't like" mean?

It looks like your code is late bound, so wdOrientLandscape has no value. Try declaring it yourself:

Code:
Const wdOrientLandscape as long = 1

and see if that helps. You also might as well just work out the value of CentimetersToPoints(1) and put that in the code.
Thank you for this, IUnfortunately it did not work, the page stayed Portrait. I am unsure how to work out the value of CentimetersToPoints though? how would i do that and what would the code look like?
 
Upvote 0
In the immediate window (Ctrl+G while in the VB Editor) type:
Code:
?centimeterstopoints(1)
and press Enter.
 
Upvote 0
What does your current code look like and which version of Mac Excel is being used?
 
Upvote 0
What does your current code look like and which version of Mac Excel is being used?
Office 365 package is being used...

This is now my code...
VBA Code:
Dim oWord As Object
Set oWord = CreateObject(Class:=("Word.application"))
oWord.Visible = True
oWord.Activate
Dim oDoc
Set oDoc = oWord.Documents.Add
Const edOrientLandscape As Long = 1
 
Upvote 0
It's wdOrientLandscape not edOrientLandscape
 
Upvote 0

Forum statistics

Threads
1,215,225
Messages
6,123,732
Members
449,116
Latest member
Aaagu

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