Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Set Page Orientation

jlegjleg Posts: 237Member
I have created a VB6 program which uses Word as its report generator. I use the following code to generate an instance of word.

Set mobjWord = GetObject("", "Word.Basic")
mobjWord.AppMinimize ("Microsoft Word")

mobjWord.FileNew

etc, etc.

I am able to manipulate the new document without any trouble. I can insert text and tables but I can't seem to change the documents page orientation. I want to change it to landscape. All of the above operations are done in the background with the application minimized.

Can someone help me out.

Thanks

John ;-)

Comments

  • PavlinIIPavlinII Posts: 404Member
    : I have created a VB6 program which uses Word as its report generator. I use the following code to generate an instance of word.
    :
    : Set mobjWord = GetObject("", "Word.Basic")
    : mobjWord.AppMinimize ("Microsoft Word")
    :
    : mobjWord.FileNew
    :
    : etc, etc.
    :
    : I am able to manipulate the new document without any trouble. I can insert text and tables but I can't seem to change the documents page orientation. I want to change it to landscape. All of the above operations are done in the background with the application minimized.
    :
    : Can someone help me out.
    :
    : Thanks
    :
    : John ;-)
    :

    Your Word start with GetObject made really crazy things with my system...
    [code]Dim xWord As Word.Application, xDocument As Word.Document

    Set xWord = CreateObject("Word.Application")
    Set xDocument = xWord.Documents.Add
    xDocument.PageSetup.Orientation = wdOrientLandscape [green]'Here we go[/green]
    xWord.Visible = True[/code]xDocument behaves like document so I suppose that you can do something like [blue]myobjWord.Workbooks(Index).[/blue]Pageblablabla...
    There could work
    [code]Dim xDocument As Word.Document

    Set xDocument = Word.Documents.Add[/code]But it made some problems today..

    Hope It's enough
    PavlinII
  • jlegjleg Posts: 237Member
    : : I have created a VB6 program which uses Word as its report generator. I use the following code to generate an instance of word.
    : :
    : : Set mobjWord = GetObject("", "Word.Basic")
    : : mobjWord.AppMinimize ("Microsoft Word")
    : :
    : : mobjWord.FileNew
    : :
    : : etc, etc.
    : :
    : : I am able to manipulate the new document without any trouble. I can insert text and tables but I can't seem to change the documents page orientation. I want to change it to landscape. All of the above operations are done in the background with the application minimized.
    : :
    : : Can someone help me out.
    : :
    : : Thanks
    : :
    : : John ;-)
    : :
    :
    : Your Word start with GetObject made really crazy things with my system...
    : [code]Dim xWord As Word.Application, xDocument As Word.Document
    :
    : Set xWord = CreateObject("Word.Application")
    : Set xDocument = xWord.Documents.Add
    : xDocument.PageSetup.Orientation = wdOrientLandscape [green]'Here we go[/green]
    : xWord.Visible = True[/code]xDocument behaves like document so I suppose that you can do something like [blue]myobjWord.Workbooks(Index).[/blue]Pageblablabla...
    : There could work
    : [code]Dim xDocument As Word.Document
    :
    : Set xDocument = Word.Documents.Add[/code]But it made some problems today..
    :
    : Hope It's enough
    : PavlinII
    :
    Thanks PavlinII

    I was hoping to get my existing code to function properly. I will give yours a go. Here is an extended version of my original code. It may explain it a little better.

    Dim mobjWord As Object

    Set mobjWord = GetObject("", "Word.Basic")
    mobjWord.AppMinimize ("Microsoft Word")

    mobjWord.FileNew

    mobjWord.FilePageSetup Orientation:=wdOrientLandscape

    *****************
    I have found out that the above is having trouble with wdOrientLandscape. If I enter a numeric value of 1 it does change the orientation. Now I'm having trouble with the pagesize itself. What happens i that when the orientation is set it changes the papersize to Custom.

    I have found another command that will allow me to toggle the paper to landscape and leave the papersize at A4. I used the following syntax

    mobjWord.TogglePortrait

    This works but the only problem is that if the page orientation is already landscape it sets it to portrait which is no good for my report design. I need to use the mobjWord Object to find out what the current orientation is and apply TogglePortrait only if the current page orientation is Portrait.

    I know that the program is not responding to "wdOrientPortrait" or any other wd parameters. However it will accept integers eg:
    mobjWord.FilePageSetup Orientation:=1 ' to orient to Landscape

    Can anyone assist a little further?

    Thanks

    John ;-)


  • PavlinIIPavlinII Posts: 404Member
    : : : I have created a VB6 program which uses Word as its report generator. I use the following code to generate an instance of word.
    : : :
    : : : Set mobjWord = GetObject("", "Word.Basic")
    : : : mobjWord.AppMinimize ("Microsoft Word")
    : : :
    : : : mobjWord.FileNew
    : : :
    : : : etc, etc.
    : : :
    : : : I am able to manipulate the new document without any trouble. I can insert text and tables but I can't seem to change the documents page orientation. I want to change it to landscape. All of the above operations are done in the background with the application minimized.
    : : :
    : : : Can someone help me out.
    : : :
    : : : Thanks
    : : :
    : : : John ;-)
    : : :
    : :
    : : Your Word start with GetObject made really crazy things with my system...
    : : [code]Dim xWord As Word.Application, xDocument As Word.Document
    : :
    : : Set xWord = CreateObject("Word.Application")
    : : Set xDocument = xWord.Documents.Add
    : : xDocument.PageSetup.Orientation = wdOrientLandscape [green]'Here we go[/green]
    : : xWord.Visible = True[/code]xDocument behaves like document so I suppose that you can do something like [blue]myobjWord.Workbooks(Index).[/blue]Pageblablabla...
    : : There could work
    : : [code]Dim xDocument As Word.Document
    : :
    : : Set xDocument = Word.Documents.Add[/code]But it made some problems today..
    : :
    : : Hope It's enough
    : : PavlinII
    : :
    : Thanks PavlinII
    :
    : I was hoping to get my existing code to function properly. I will give yours a go. Here is an extended version of my original code. It may explain it a little better.
    :
    : Dim mobjWord As Object
    :
    : Set mobjWord = GetObject("", "Word.Basic")
    : mobjWord.AppMinimize ("Microsoft Word")
    :
    : mobjWord.FileNew
    :
    : mobjWord.FilePageSetup Orientation:=wdOrientLandscape
    :
    : *****************
    : I have found out that the above is having trouble with wdOrientLandscape. If I enter a numeric value of 1 it does change the orientation. Now I'm having trouble with the pagesize itself. What happens i that when the orientation is set it changes the papersize to Custom.
    :
    : I have found another command that will allow me to toggle the paper to landscape and leave the papersize at A4. I used the following syntax
    :
    : mobjWord.TogglePortrait
    :
    : This works but the only problem is that if the page orientation is already landscape it sets it to portrait which is no good for my report design. I need to use the mobjWord Object to find out what the current orientation is and apply TogglePortrait only if the current page orientation is Portrait.
    :
    : I know that the program is not responding to "wdOrientPortrait" or any other wd parameters. However it will accept integers eg:
    : mobjWord.FilePageSetup Orientation:=1 ' to orient to Landscape
    :
    : Can anyone assist a little further?
    :
    : Thanks
    :
    : John ;-)
    :
    :
    :
    Hi, it's MS Word 95, isn't it? I'm sorry, it's too deep history (I didn't found instalation so I couldn't simulate it)...
    On '97 it works and on 2k too..

    So only general advices:
    [gray]About TogglePortrait - if this don't have problems with pagesizes, there must exist way how to get actual value of FilePageSetup.Orientation.. So why do not use "if PageSetup Orientation..." (I don't know systax exactly, I couldn't simulate it) "Then PageSetup.TogglePortrail...."[/gray]

    And another (may be more useful way) - here are sizes of landscape paper: When you set Orientaion=wdOrientationLandscape (=1), you may set sizes like this:
    [code][green]'I took variables from W'97[/green]
    .LineNumbering.Active = True
    .Orientation = wdOrientLandscape [green]'1[/green]
    .TopMargin = CentimetersToPoints(2.5) [green]'70,86614[/green]
    .BottomMargin = CentimetersToPoints(2.5) [green]'70,86614[/green]
    .LeftMargin = CentimetersToPoints(2.5) [green]'70,86614[/green]
    .RightMargin = CentimetersToPoints(2.5) [green]'70,86614[/green]
    .Gutter = CentimetersToPoints(0) [green]'0[/green]
    .HeaderDistance = CentimetersToPoints(1.25) [green]'35,43307[/green]
    .FooterDistance = CentimetersToPoints(1.25) [green]'35,43307[/green]
    .PageWidth = CentimetersToPoints(29.7) [green]'841,8898[/green]
    .PageHeight = CentimetersToPoints(21) [green]'595,2756[/green]
    .FirstPageTray = wdPrinterDefaultBin [green]'0[/green]
    .OtherPagesTray = wdPrinterDefaultBin [green]'0[/green]
    .SectionStart = wdSectionNewPage [green]'2[/green]
    .OddAndEvenPagesHeaderFooter = False
    .DifferentFirstPageHeaderFooter = False
    .VerticalAlignment = wdAlignVerticalTop [green]'0[/green]
    .SuppressEndnotes = False
    .MirrorMargins = False
    [green]'These two are additional in '2k - for completeness'sake[/green]
    .TwoPagesOnOne = False
    .GutterPos = wdGutterPosLeft [green]'0[/green][/code]
    I wrote the real values to make sure.. what if it don't know CentimetersToPoints...

    I suppose that if you set all those values, it must work..

    PavlinII

  • jlegjleg Posts: 237Member
    : : : : I have created a VB6 program which uses Word as its report generator. I use the following code to generate an instance of word.
    : : : :
    : : : : Set mobjWord = GetObject("", "Word.Basic")
    : : : : mobjWord.AppMinimize ("Microsoft Word")
    : : : :
    : : : : mobjWord.FileNew
    : : : :
    : : : : etc, etc.
    : : : :
    : : : : I am able to manipulate the new document without any trouble. I can insert text and tables but I can't seem to change the documents page orientation. I want to change it to landscape. All of the above operations are done in the background with the application minimized.
    : : : :
    : : : : Can someone help me out.
    : : : :
    : : : : Thanks
    : : : :
    : : : : John ;-)
    : : : :
    : : :
    : : : Your Word start with GetObject made really crazy things with my system...
    : : : [code]Dim xWord As Word.Application, xDocument As Word.Document
    : : :
    : : : Set xWord = CreateObject("Word.Application")
    : : : Set xDocument = xWord.Documents.Add
    : : : xDocument.PageSetup.Orientation = wdOrientLandscape [green]'Here we go[/green]
    : : : xWord.Visible = True[/code]xDocument behaves like document so I suppose that you can do something like [blue]myobjWord.Workbooks(Index).[/blue]Pageblablabla...
    : : : There could work
    : : : [code]Dim xDocument As Word.Document
    : : :
    : : : Set xDocument = Word.Documents.Add[/code]But it made some problems today..
    : : :
    : : : Hope It's enough
    : : : PavlinII
    : : :
    : : Thanks PavlinII
    : :
    : : I was hoping to get my existing code to function properly. I will give yours a go. Here is an extended version of my original code. It may explain it a little better.
    : :
    : : Dim mobjWord As Object
    : :
    : : Set mobjWord = GetObject("", "Word.Basic")
    : : mobjWord.AppMinimize ("Microsoft Word")
    : :
    : : mobjWord.FileNew
    : :
    : : mobjWord.FilePageSetup Orientation:=wdOrientLandscape
    : :
    : : *****************
    : : I have found out that the above is having trouble with wdOrientLandscape. If I enter a numeric value of 1 it does change the orientation. Now I'm having trouble with the pagesize itself. What happens i that when the orientation is set it changes the papersize to Custom.
    : :
    : : I have found another command that will allow me to toggle the paper to landscape and leave the papersize at A4. I used the following syntax
    : :
    : : mobjWord.TogglePortrait
    : :
    : : This works but the only problem is that if the page orientation is already landscape it sets it to portrait which is no good for my report design. I need to use the mobjWord Object to find out what the current orientation is and apply TogglePortrait only if the current page orientation is Portrait.
    : :
    : : I know that the program is not responding to "wdOrientPortrait" or any other wd parameters. However it will accept integers eg:
    : : mobjWord.FilePageSetup Orientation:=1 ' to orient to Landscape
    : :
    : : Can anyone assist a little further?
    : :
    : : Thanks
    : :
    : : John ;-)
    : :
    : :
    : :
    : Hi, it's MS Word 95, isn't it? I'm sorry, it's too deep history (I didn't found instalation so I couldn't simulate it)...
    : On '97 it works and on 2k too..
    :
    : So only general advices:
    : [gray]About TogglePortrait - if this don't have problems with pagesizes, there must exist way how to get actual value of FilePageSetup.Orientation.. So why do not use "if PageSetup Orientation..." (I don't know systax exactly, I couldn't simulate it) "Then PageSetup.TogglePortrail...."[/gray]
    :
    : And another (may be more useful way) - here are sizes of landscape paper: When you set Orientaion=wdOrientationLandscape (=1), you may set sizes like this:
    : [code][green]'I took variables from W'97[/green]
    : .LineNumbering.Active = True
    : .Orientation = wdOrientLandscape [green]'1[/green]
    : .TopMargin = CentimetersToPoints(2.5) [green]'70,86614[/green]
    : .BottomMargin = CentimetersToPoints(2.5) [green]'70,86614[/green]
    : .LeftMargin = CentimetersToPoints(2.5) [green]'70,86614[/green]
    : .RightMargin = CentimetersToPoints(2.5) [green]'70,86614[/green]
    : .Gutter = CentimetersToPoints(0) [green]'0[/green]
    : .HeaderDistance = CentimetersToPoints(1.25) [green]'35,43307[/green]
    : .FooterDistance = CentimetersToPoints(1.25) [green]'35,43307[/green]
    : .PageWidth = CentimetersToPoints(29.7) [green]'841,8898[/green]
    : .PageHeight = CentimetersToPoints(21) [green]'595,2756[/green]
    : .FirstPageTray = wdPrinterDefaultBin [green]'0[/green]
    : .OtherPagesTray = wdPrinterDefaultBin [green]'0[/green]
    : .SectionStart = wdSectionNewPage [green]'2[/green]
    : .OddAndEvenPagesHeaderFooter = False
    : .DifferentFirstPageHeaderFooter = False
    : .VerticalAlignment = wdAlignVerticalTop [green]'0[/green]
    : .SuppressEndnotes = False
    : .MirrorMargins = False
    : [green]'These two are additional in '2k - for completeness'sake[/green]
    : .TwoPagesOnOne = False
    : .GutterPos = wdGutterPosLeft [green]'0[/green][/code]
    : I wrote the real values to make sure.. what if it don't know CentimetersToPoints...
    :
    : I suppose that if you set all those values, it must work..
    :
    : PavlinII
    :
    :
    Thanks PavlinII

    I've thought of doing it the way you suggest. There are obviously some syntax differences when the object is created by either GetObject or CreateObject. I can't seem to find the code for checking the current page orientation using GetObject

    If mobjWord.FilePageSetup Orientation = 1 Then
    'DoNothing
    Else
    MobjWord.FilePageSetup Orientation:=1
    End If

    Doesn't seem to work.

    As I said before I found if you change the orientation of the page the paper type goes to Custom. I did find on the Microsoft site that if any measurements are changed with a page that Custom is automatically set. If I change the page orientation with Toggle the Page remains at A4.

    John ;-)

Sign In or Register to comment.