Results 1 to 2 of 2
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    obtaining page orientation returns nothing? (Word97 sr2a)

    Hi all

    I'm writing code to insert hole punch symbols into all documents.

    I obtain the current page setup orientation & check
    ie if page setup is portrait then insert the portrait hole punch symbol.
    If page setup is landscape then insert the landscape hole punch symbol.

    The issue is:
    my variable to store the page orientation doesnt return a valid value.
    ie returns 'nothing'
    or if I define variable as integer always returnts '0' even if orientation has changed.

    Is the way I defined my variable incorrect?
    or how I'm obtaining the orientation in a range incorrect?
    can someone please assist - many thanks Diana


    Sub HolePunchSymbolInsert()

    Dim sectionThis As Section
    Dim headerThis As HeaderFooter
    Dim iPageOrientation As PageSetup
    'Dim iPageOrientation As Integer
    Dim rngThis As Range
    Dim strAutoTextTemplate As String
    Dim strHolePunchSymbol As String
    Dim i%, j%

    x = 0

    For Each sectionThis In ActiveDocument.Sections
    For j = 1 To 3
    Set rngThis = Nothing
    On Error Resume Next

    Select Case j
    Case 1
    Set rngThis = sectionThis.Headers(wdHeaderFooterFirstPage).Range
    Case 2
    Set rngThis = sectionThis.Headers(wdHeaderFooterPrimary).Range
    Case 3
    Set rngThis = sectionThis.Headers(wdHeaderFooterEvenPages).Range
    End Select

    iPageOrientation = 0
    'for formatting purposes obtain current section page orientation
    iPageOrientation = sectionThis.PageSetup.Orientation

    'if page setup orientation is landscape -set hole punch to be landscaped
    'format object within page orientation & margins
    If iPageOrientation = 1 Then
    'If iPageOrientation = wdOrientLandscape Then
    strHolePunchSymbol = "HolePunchLandscape"

    'else if page setup orientation is portrait -set hole punch to be portrait
    ElseIf iPageOrientation = 0 Then
    'ElseIf iPageOrientation = wdOrientPortrait Then
    strHolePunchSymbol = "HolePunchPotrait"
    End If

    'select current header
    rngThis.Select
    rngThis.Collapse Direction:=wdCollapseEnd
    Selection.Collapse Direction:=wdCollapseEnd

    'insert autotext entry for hole punch
    strAutoTextTemplate = gcCCWGlobalRootDirectory & "CorrsAutotext.dot"
    If AddIns(strAutoTextTemplate).Installed Then
    Templates(strAutoTextTemplate).AutoTextEntries(str HolePunchSymbol).Insert Where:=Selection.Range, RichText:=True
    End If

    Next
    Next

    'call functions to reset users word environment

    End Sub

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: obtaining page orientation returns nothing? (Word97 sr2a)

    This line

    Dim iPageOrientation As PageSetup

    could be the problem. First try changing that back to an integer. Or you could bypass that by doing this:

    'if page setup orientation is landscape -set hole punch to be landscaped
    'format object within page orientation & margins
    If sectionThis.PageSetup.Orientation = 1 Then
    strHolePunchSymbol = "HolePunchLandscape"

    'else if page setup orientation is portrait -set hole punch to be portrait
    ElseIf sectionThis.PageSetup.Orientation = 0 Then
    strHolePunchSymbol = "HolePunchPotrait"
    End If

    Hope this helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •