Modeless Userform in Word 97

M

Mike Iacovou

Hi all,

I have stumbled on some code to make UserForms in Excel 97 modeless. This is
achieved using some Windows API calls - and requires that cell drag 'n drop
be disabled for the application as it can result in a General Protection
Fault.
I haven't tried the code below (which should be inserted into the userform
code) in Word 97, but it follows the same lines as that for Excel (with the
exception that I have swapped the application class to Word).

If anyone has tried this (or is aware of tests etc), are there any 'side
effects' or funstions that would need ot be disabled to prevent crashes /
GPFs etc (as in the Excel example). This is something that will only be known
by experience / experimentation (I couldn't find any reference of this being
tried, let alone any problems).

Any experience greatly appreciated. TIA

Mike

'Code to insert into UserForm. I have used conditional so that it only
executes if Word 97 - and will be ignored on 2000+ where have modeless forms
etc.

Private Declare Function FindWindowA Lib "user32" (ByVal lpClassName As
String, ByVal lpWindowName As String) As Long
Private Declare Function EnableWindow Lib "user32" (ByVal hWnd As Long,
ByVal bEnable As Long) As Long

Dim mlHWnd As Long

Private Sub UserForm_Activate()
#If VBA6 Then
'Do nothing - form should be modeless from XL2000+
#Else
On Error Resume Next
'Find the Excel main window
mlHWnd = FindWindowA("OpusApp", Application.Caption)

'Enable the Window - makes the userform modeless
EnableWindow mlHWnd, 1
#End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top