Hi
I am getting error:
Run-time error '1004': Unable to set the Orientation property of the PageSetup class
I am using the following code:
In the .Orientation = StrOrientation section I have replaced the variable with "xlPortrait" and it works so I know it isn't a printer issue. I have entered the variable reference in incorrectly but I cannot work out where or how.Code:Dim StrOrientation As String Application.Goto Reference:="Orientation" StrOrientation = Activecell.Value 'where reference is either xlPortrait of xlLandscape With ActiveSheet.PageSetup .Orientation = StrOrientation End With
Thanks in advance
Last edited by froodo; 07-08-2009 at 09:25 PM. Reason: code tag
Hi froodo,
Welcome to the forum.
I may have a solution, but before I can suggest it you'll need to PM a moderator to have your code wrapped as your thread currently breaks Rule 3 of the forum (see here for more info).
Once this is done I'll gladly post my suggested solution.
Regards,
Robert
____________________________________________
Please ensure you mark your thread as Solved once it is. Click here to see how
If this post helps, please don't forget to add to our reputation by clicking the blue scale icon in the top right-hand corner of my post
Hi froodo,
Thanks for that.
As you've created a named range you don't have to assign its value to variable, i.e.
will work fine. If you really want to assign the value of the "Orientation" named range to a variable (which seems to me to be doubling handling), try this:Code:Sub Macro1() With ActiveSheet.PageSetup .Orientation = Range("Orientation").Value End With End Sub
HTHCode:Sub Macro2() Dim strOrientation As String strOrientation = Range("Orientation").Value With ActiveSheet.PageSetup .Orientation = strOrientation End With End Sub
Robert
____________________________________________
Please ensure you mark your thread as Solved once it is. Click here to see how
If this post helps, please don't forget to add to our reputation by clicking the blue scale icon in the top right-hand corner of my post
Thanks for your reply and help with forum etiquette, I still am receiving the same error when I use either of your methods. Any other ideas what may be wrong?
Thanks
Hi froodo,
The orientation options (i.e. Portrait or Landscape) must be returned as integers (1 or 2 respectively).
Have a look at the following which checks the value in the "Orientation" named range to assign one of the two values to the "intPrintOrientation" accordingly. I've also included some notes to hopefully explain things:
HTHCode:Sub Macro3() 'Declare variable Dim intPrintOrientation As Integer 'If any part of the named range "Orientation" has _ 'Portrait' in it then... If InStr(Range("Orientation").Value, "Portrait") > 0 Then '...assign 1 (integer value for portrait) to the _ 'intPrintOrientation' variable. intPrintOrientation = 1 'Else... Else '...assign 2 (integer value for landscape) to the _ 'intPrintOrientation' variable (this will therefore _ be the default). intPrintOrientation = 2 End If With ActiveSheet .PageSetup.Orientation = intPrintOrientation .PrintOut Copies:=1 End With End Sub
Robert
____________________________________________
Please ensure you mark your thread as Solved once it is. Click here to see how
If this post helps, please don't forget to add to our reputation by clicking the blue scale icon in the top right-hand corner of my post
Thanks, that did the trick. I was thinking that the xlLandscape and xlPortrait would of have to of been used.
Cheers
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks