Visual Basic 6 & Excel 2010 Page Orientation


I am creating a Visual Basic 6 project to copy data out of an Access file and put it in a new Excel 2010 file.
I've gotten my data extracted properly from my Access file but I'm trying to format the Page Layout my new Excel 2010 file from within my Visual Basic 6 project.
Several of my Page Layout modifications have worked fine but setting the "Orientation" to 'Landscape' has not worked so far. Either I get errors at runtime or it just doesn't change the Page Layout, "Orientation" to 'Landscape'.

So far, I used the below code to change some layout settings and they work fine:
sheet.PageSetup.CenterHeader = _
"&""Times New Roman,Bold""&12My Company" & Chr(10) & "Report"
sheet.PageSetup.RightHeader = "&""Times New Roman,Bold""&12&D &T"
sheet.PageSetup.CenterFooter = "&""Times New Roman,Bold""&12Page &P of &N"
sheet.PageSetup.PrintGridlines = True

NOTE: "sheet" is 'Set sheet = book.Worksheets(1)'
If I add the below line after the 'PrintGridLines' statement shown above, it runs without error but the "Orientation" does not get changed and none of the 'Layout' changes show above get changed?:
sheet.PageSetup.Orientation = xlLandscape

Any help would be greatly appreciated.
Thanks in advance.
Curt

If you enjoyed this post, subscribe for updates (it's free)

Figured Out:Visual Basic 6 & Excel 2010 Page Orientation

I figured out that I needed to add a "Reference" to the 'Microsoft Excel 14.0 Object Library'. I didn't have this "Reference" set and it wouldn't do the "Align" to 'Landscape' without it. Once I went to the "Project" pull-down menu, clicked on "References" and then added a check next to the 'Microsoft Excel 14.0 Object Library', it worked fine.
I no longer need help with this issue.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. The supported tag styles are: <foo>, [foo].

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.