Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Mar 2002
    Location
    Connecticut, USA
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Inconsistent behavior inside Frame (2000)

    Hi All,

    I'm having the weirdest problem. I have two sub routines (plus one helper routine) that basically do the same thing. One consistently fails. The other sometimes works sometimes fails (running under exactly the same circumstances mind!)

    The macros each do the following
    1. Insert a Frame on the right side of the page.
    2. Enter some text and formatting on the first line.
    3. Create a new paragraph.
    4. Enter some text and formatting on the second line.

    There is a helper Function called MakeStandardFrame that just creates and returns a frame.

    The first macro is LowHighLine(). When I run this one sometimes it creates both paragraphs in the frame, sometimes is just creates one paragraph incorrectly. I'm consistently running it with no text in the document and the first paragraph highlighted.

    The second macro is IndVerLine(). This one consistently fails to create both paragraphs and creates one incorrectly instead.

    I've tried a few dozen ways to fix this including significant rewrites. I've recorded myself doing these actions and again sometimes it works sometimes it doesn't.

    ANY help would be most appreciated. I have to create about 30 of these!!

    Regards,

    Peter

    Code Below:

    Function MakeStandardFrame(Optional HPos As WdFramePosition = wdFrameRight, Optional FixedWidth As Single = 1, Optional FixedHeight As Single = 0.3) As Frame
    'Anything selected will end up in the frame so collapes selection
    Selection.Collapse Direction:=wdCollapseStart
    Dim frm As Frame
    Set frm = ActiveDocument.Frames.Add(Selection.Range)
    'Frame on right side, no borders, fixed width,
    'move with para, Arial 12 pt contents, no tabs
    With frm
    .TextWrap = True
    .WidthRule = wdFrameExact
    .Width = InchesToPoints(FixedWidth)
    .HeightRule = wdFrameExact
    .Height = InchesToPoints(FixedHeight)
    .HorizontalPosition = HPos
    .RelativeHorizontalPosition = wdRelativeHorizontalPositionMargin
    .VerticalPosition = InchesToPoints(0)
    .RelativeVerticalPosition = wdRelativeVerticalPositionParagraph
    .HorizontalDistanceFromText = InchesToPoints(0.13)
    .VerticalDistanceFromText = InchesToPoints(0)
    .LockAnchor = False
    With .Borders
    .OutsideLineStyle = wdLineStyleNone
    .Shadow = False
    End With
    With .Range.Font
    .Name = "Arial"
    .Size = 12
    End With
    .Range.Paragraphs.TabStops.ClearAll
    End With
    'Return frame for further processing if calling proc needs.
    Set MakeStandardFrame = frm
    End Function

    '************************************************* ***********
    '* Toolbar Button Procedures - In order on toolbar
    '************************************************* ***********
    Public Sub LowHighLine()
    Dim frm As Frame
    Set frm = MakeStandardFrame(FixedHeight:=0.46)
    'Write First Line
    With frm.Range.ParagraphFormat.TabStops
    .ClearAll
    .Add Position:=InchesToPoints(0.42), Alignment:=wdAlignTabRight
    .Add Position:=InchesToPoints(0.75), Alignment:=wdAlignTabRight
    .Add Position:=InchesToPoints(1), Alignment:=wdAlignTabRight
    End With
    frm.Range.Select
    With Selection
    .TypeText vbTab
    .Font.Underline = wdUnderlineSingle
    .TypeText vbTab & "/" & vbTab
    .Collapse Direction:=wdCollapseEnd
    .TypeParagraph
    End With
    'Write Second Line
    With Selection.Range.ParagraphFormat.TabStops
    .ClearAll
    .Add Position:=InchesToPoints(0.42), Alignment:=wdAlignTabLeft
    .Add Position:=InchesToPoints(1), Alignment:=wdAlignTabLeft
    End With
    With Selection
    .Font.Underline = wdUnderlineNone
    .Font.Size = 10
    .TypeText vbTab & "Low High"
    End With
    End Sub

    Public Sub IndVerLine()
    Dim frm As Frame
    Set frm = MakeStandardFrame(FixedHeight:=2, FixedWidth:=3)
    'Write First Line
    'frm.Range.Select
    With frm.Range.ParagraphFormat.TabStops
    .ClearAll
    .Add Position:=InchesToPoints(0.52), Alignment:=wdAlignTabRight
    .Add Position:=InchesToPoints(0.78), Alignment:=wdAlignTabRight
    .Add Position:=InchesToPoints(0.98), Alignment:=wdAlignTabRight
    .Add Position:=InchesToPoints(1), Alignment:=wdAlignTabRight
    End With
    frm.Range.Select
    With Selection
    .TypeText Text:=vbTab
    .Font.Underline = wdUnderlineSingle
    .TypeText Text:=vbTab & "/" & vbTab
    .Font.Size = 10
    .TypeText Text:="*"
    .Font.Size = 12
    .TypeText Text:=vbTab
    .Collapse Direction:=wdCollapseEnd
    .TypeParagraph
    End With
    With Selection.ParagraphFormat.TabStops
    .ClearAll
    .Add Position:=InchesToPoints(0.51), Alignment:=wdAlignTabLeft
    .Add Position:=InchesToPoints(1), Alignment:=wdAlignTabLeft
    End With
    With Selection
    .Font.Underline = wdUnderlineNone
    .Font.Size = 10
    .TypeText vbTab & "Ind.Ver."
    End With
    End Sub

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Inconsistent behavior inside Frame (2000)

    Hi Peter,

    After playing around with this for a while, and trying any workarounds that came to mind, I'm getting the same results you report - sometimes it works and sometimes it doesn't.

    This behavior is among the hardest to troubleshoot, but usually means either a) some environment variable is being left set, which is affecting the code next time it runs, or [img]/forums/images/smilies/cool.gif[/img] you are dealing with a buggy Word/VBA object implementation.

    Since the former doesn't seem likely with this code, I'm putting my bet on the latter. Perhaps with some more hacking a workaround will be found, but in the meantime my next question is: do you have any alternatives to doing what you're trying to do, the way you are trying to do it?

    Gary

  3. #3
    New Lounger
    Join Date
    Mar 2002
    Location
    Connecticut, USA
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Inconsistent behavior inside Frame (2000)

    Thanks Gary!

    Sometimes the best thing is just to confirm that you're not crazy!

    I was finally able to get it to work. In case your interested here is the test (that didn't work!) that helped me find a way around.

    *****
    'Code to create frame and put into frm variable

    frm.Range.Select ' Doesn't seem to select range - just puts cursor in first paragraph
    Selection.InsertParagraph
    Selection.InsertParagraph
    Selection.InsertParagraph
    Selection.InsertParagraph
    'When you step through this it seems that after the InsertParagraph there is NO SELECTION at all.
    'Then if you step again there is a cursor, then no selection, then cursor, etc.

    *******

    Anyway, I used the fact that frm.Range.Select just put the cursor in the first paragraph and did it a different way. Very buggy though!

    Here is the subroutine that worked (and I used this technique for the other 30!)

    *******

    Public Sub IndVerLine2()
    Dim frm As Frame
    Set frm = MakeStandardFrame(FixedHeight:=0.46)
    'Write First Line
    frm.Range.Select
    Selection.Range.InsertParagraphAfter
    Selection.Collapse wdCollapseStart
    With Selection.ParagraphFormat.TabStops
    .ClearAll
    .Add Position:=InchesToPoints(0.52), Alignment:=wdAlignTabRight
    .Add Position:=InchesToPoints(0.78), Alignment:=wdAlignTabRight
    .Add Position:=InchesToPoints(0.98), Alignment:=wdAlignTabRight
    .Add Position:=InchesToPoints(1), Alignment:=wdAlignTabRight
    End With
    With Selection
    .TypeText Text:=vbTab
    .Font.Underline = wdUnderlineSingle
    .TypeText Text:=vbTab & "/" & vbTab & vbTab
    .Collapse Direction:=wdCollapseEnd
    End With
    Selection.MoveDown Unit:=wdParagraph, Count:=1
    With Selection.ParagraphFormat.TabStops
    .ClearAll
    .Add Position:=InchesToPoints(0.51), Alignment:=wdAlignTabLeft
    .Add Position:=InchesToPoints(1), Alignment:=wdAlignTabLeft
    End With
    With Selection
    .Font.Underline = wdUnderlineNone
    .Font.Size = 10
    .TypeText vbTab & "Ind.Ver."
    End With
    End Sub


    *******

    Note the Selection.MoveDown hack. A little clunky, but it worked.

    Thanks for your help.

    Regards,

    Peter

Posting Permissions

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