Consulting

Results 1 to 4 of 4

Thread: form show Modal to Modeless and back again

  1. #1
    VBAX Regular
    Joined
    Mar 2018
    Location
    Leesburg
    Posts
    68
    Location

    form show Modal to Modeless and back again

    Hello, I have a userform that is shown in modal form.
    On that form I have a help button that, when clicked, opens up another word document (user guide) and, using bookmarks, goes to the right area in the document that pertains to that userform, thereby supplying the ability for the user to read detailed guidance information.

    The problem, of course, is the userform needs to be modal to prevent the user from off-clicking the form and doing other things in word that will confuse the program.

    I have tried the below code which successfully hides the userform, opens the user guide, goes to the proper bookmark, and then, once the user closes the user guide (or switches back to the original document), redisplays the userform, but the userform is now displayed modeless form. If I try to change it back to modal form (Me.Show 1), it displays instead of the user guide. Is there any way, once focus is returned to the userform, to then change the form back to a modal state?

    I know that this may seem like a strange exercise, but the user guide is 200+ pages long so I cannot simply add all that data into the program itself. The program has dozens of userforms for a variety of functions, all covered in detail in the user guide. From what I have read, trying to use MSFT's help facility would be really painful. I also toyed with the idea of converting the user guide to Adobe PDF which would then be readable when a Word userform is in a modal state, but Adobe doesn't support Word bookmarks.

    Any suggestions?

    Private Sub cmdHelp_Click()
        Me.Hide
        Dim wdApp As Object
        Dim wdDoc As Object
        Dim strUserGuide As String
        On Error Resume Next
        Set wdApp = GetObject(, "Word.Application")
        If Err Then
            Set wdApp = CreateObject("Word.Application")
        End If
        On Error GoTo 0
        strUserGuide = Environ("USERPROFILE") & "\My Documents\[folder]\[user guide name].docx"
        Set wdDoc = wdApp.Documents.Open(FileName:=strUserGuide)
        wdDoc.range.Bookmarks("[BookmarkName]").Select
        wdApp.Activate
        Me.Show 0
    End Sub

  2. #2
    VBAX Expert Dave's Avatar
    Joined
    Mar 2005
    Posts
    835
    Location
    Maybe run a timer to check when the Word document has closed? Call the sub before the end of the command sub. Untested. HTH. Dave
    Public Sub CheckWordApp()
    Dim Temp As Object
    Before:
    Call Waitatime
    'action to shut off loop
    On Error Resume Next
    Set Temp = WdApp.ActiveDocument
    If Err.Number <> 0 Then
    On Error GoTo 0
    Me.Show 1 '** replace Me with actual userform name
    Set Temp = Nothing
    Exit Sub
    Else
    GoTo Before
    End If
    End Sub
    
    Function Waitatime()
    Dim PauseTime, start
        PauseTime = 1    ' Set duration.
        start = Timer    ' Set start time.
        Do While Timer < start + PauseTime
            DoEvents    ' Yield to other processes.
        Loop
    End Function

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    If you're already in Word when you show the first UF, instead of creating another instance of Word, could you open a second (i.e. The Help doc), and do what you need to do?

    I'm guessing (bold, underlined) that the second instance might be causing the problem
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #4
    VBAX Regular
    Joined
    Mar 2018
    Location
    Leesburg
    Posts
    68
    Location
    Thanks Paul and Dave, for your ideas. After playing around with this more, I decided to bite the bullet and build an HTML help file. The code links to it quite nicely and it all is working well. I went to send it out to my team today and discovered that our IT dept strips .chm attachment files in Outlook (but allows .dotm files!). The pain, the pain.

Tags for this Thread

Posting Permissions

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