Results 1 to 7 of 7
  1. #1
    New Lounger
    Join Date
    May 2001
    Location
    Blackpool, Lancashire, England
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Word VBA Modal userform issues and hiding userform (engvba/word/xp)

    I am developing a large word document template that presents the user with a user form front end, collects the data on completion at goes on to be built by one of many build routines. Intending it to appear as close to a standalone application (VB not allowed!) as possible and controlling the users interaction as tightly as possible, I have taken control of all exit operations toolbar and menu's, document hiding, version and naming conventions etc. What remains to totally stymie myself and collegues are:
    Modal seemed best option to adopt, binding the form and the document and ensuring control focus, this however presents us with the scenario that any word documents already open are not accessible! Their on the taskbar but clicking yields no change in application or document activation. Unfortunately our users are not guarenteed IT competents so the best instructions in the world are not going to prevent them having documents open prior to opening our template, as well as the fact that this just shouldnt happen! Any help in a workaround enabling normal multi window operation would be appreciated. Obviously were the documents only available through the windows menu like the old days this query would be mute but hopefully....
    Secondly I would also like the give the user a virtual minimize facility without resorting to form resizing! maybe by shooting the window off screen with a command button. How though can I get it back by for example using the task bar icon. I have explored the document and form event handlers (inc hooked events) to no avail.
    My apologies for such a long and verbose posting. JasH

  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: Word VBA Modal userform issues and hiding userform (engvba/word/xp)

    I haven't tested this theory, but... modal-ness (modal-ity?) should affect only a single instance of Word. You could do something to guarantee that your template launches in a completely new instance of Word. One way you might be able to do this is to use the CreateObject("Word.Application") type of automation to "re-launch" the template if the user opens it into a session of Word that has other documents open. I'd be really interested to hear if that works, since trying to make a nonmodal dialog seem modal through code would be so much more difficult.

    Regarding a "restore button," perhaps you can show a floating toolbar or a nonmodal userform with a single button? I guess the question is can you carefully hide the main userform during this time and then unhide it without re-initializing all the fields. I would hope so, but I haven't tested that notion.

    (Not sure this helped, but in 5 minutes that all I can do.)

  3. #3
    New Lounger
    Join Date
    May 2001
    Location
    Blackpool, Lancashire, England
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word VBA Modal userform issues and hiding userform (engvba/word/xp)

    Thx for rapid reply, certainly sounds feasable and will be giving a go shortly, though I'm not sure how I close and application/document instance from within itself!? Anyway, will you know how it goes. Chrs JasH

  4. #4
    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: Word VBA Modal userform issues and hiding userform (engvba/word/xp)

    Well.... I've attached a test approach. It does seem that the first instance of Word keeps the template "in use," so for editing it's a hassle, but from the user's perspective, perhaps it's okay. The bigger problem appears to be that I get the wrong window in front. Hmmm...

  5. #5
    New Lounger
    Join Date
    May 2001
    Location
    Blackpool, Lancashire, England
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word VBA Modal userform issues and hiding userform (engvba/word/xp)

    Two of us had a play yesterday, one on the modality problems (based upon your reply) and me on the seperate user form min/max solution. It turned out the later solved both problems!!!
    These are the methods for the mini user form containing one button
    Private Sub cmdRestoreWizard_Click()
    Unload Me
    With frmCNP
    .Show
    .Top = (Application.UsableHeight / 2) - (frmCNP.Height / 2)
    .Left = (Application.UsableWidth / 2) - (frmCNP.Width / 2)
    End With
    End Sub
    Private Sub UserForm_Initialize()
    Me.Top = 0
    Me.Left = 0
    End Sub
    'disables userform x button
    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    If CloseMode = vbFormControlMenu Then
    MsgBox "Please use the 'Restore' command button to exit ", vbInformation
    Cancel = 1
    ElseIf CloseMode = vbAppWindows Then
    MsgBox "Please use the 'Restore' command button to exit", vbInformation
    Cancel = 1
    End If
    End Sub

    And this is the code from the main user form as an event method for a minimize command button
    Private Sub cmdMinimize_Click()
    Me.Hide
    frmRestoreWindow.Show
    End Sub

    All very simple stuff but by making the miniform non modal, a side effect is instant access to all those documents locked up by the main and essentially modal form!

    I'll still try and produce a solution thru the application instance path, though it will have to wait a bit. Thanks vmuch again JasH

  6. #6
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word VBA Modal userform issues and hiding user

    Jefferson, I'm here because I was looking for something like "I get the wrong window in front." (<!post=Word VBA Modal userform issues,341897>Word VBA Modal userform issues<!/post>, and I want, later, to ask you about modal issues).

    In the meantime, I salvaged this code from your attachment, and I'm puzzled, because I've been searching the VBA forum for code (which I believe exists) to test - from Excel - if Word is loaded, and until I stumbled across your attachment, had failed to find any.

    I'd appreciate your comments.<pre>Public Function blnIsWordLoaded() As Boolean
    blnIsWordLoaded = False
    On Error GoTo Failed
    ' Get a handle to ourselves
    Dim docTemp As Document
    Set docTemp = ActiveDocument
    blnIsWordLoaded = True
    '''' If Documents.Count > 1 Then
    '''' Else
    '''' End If
    Failed:
    'Sub TESTblnIsWordLoaded()
    ' MsgBox blnIsWordLoaded
    'End Sub
    End Function</pre>


  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Word VBA Modal userform issues and hiding user

    The following function will tell you from another application (such as Excel or PowerPoint) whether Word is loaded:

    Function IsWordLoaded() As Boolean
    Dim wrdApp As Object

    On Error Resume Next

    Set wrdApp = GetObject(, "Word.Application")
    IsWordLoaded = Not (wrdApp Is Nothing)
    Set wrdApp = Nothing
    End Function

    Alternatively, put the following declaration at the top of the module:

    Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

    and use this function:

    Function IsWordLoaded() As Boolean
    IsWordLoaded = FindWindow("OpusApp", vbNullString)
    End Function

Posting Permissions

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