Results 1 to 2 of 2
  1. #1
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Timing problem? (VBA5)

    I use the following code to look for and if necesssary create a new style (SetupList) in Word 97 SR 2
    -----------------------------------------------------
    Private Sub Create_SetupList()

    For i = 1 To ActiveDocument.Styles.Count
    If ActiveDocument.Styles(i) = "SetupList" Then
    i = ActiveDocument.Styles.Count
    SetupList_Exists = True
    End If
    Next i

    If Not SetupList_Exists Then
    ActiveDocument.Styles.Add Name:="SetupList", Type:= _
    wdStyleTypeParagraph
    With ActiveDocument.Styles("SetupList")
    .AutomaticallyUpdate = False
    .BaseStyle = "Body Text"
    .NextParagraphStyle = "SetupList"
    End With
    End If

    End Sub
    -----------------------------------------------


    If the procedure is called only once, later in the module the following line

    Selection.Style = ActiveDocument.Styles("SetupList")

    causes error 5941 "The requested member of the collection does not exist". Sure enough, the style has not been created. Yet when the module is stepped through, or the procedure is called twice; the module runs error free.

    Any clarification would be appreciated.

    Thanks
    Don
    Regards
    Don

  2. #2
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Warrington (Greater Manchester area)/Cheshire, UK
    Posts
    153
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Timing problem? (VBA5)

    Try putting in a DoEvents just before the line which gives the error.
    That should give the system the breather and needed chance to catchup and actually create the collection.

    Hope this helps!

    James

Posting Permissions

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