I am using VBA with Word 2003. I have a UserForm (frmGraphicInsert) that automates the insertion of graphics into the document. The form opens modally (default).
Clicking an image on the UserForm opens the wdDialogInsertPicture built-in dialog (dialogs collection). When this happens, the UserForm mysteriously becomes modeless and the document window becomes active (ie. the UserForm loses focus).
1) Why does this happen?
2) Is there a workaround?
3) Once a UserForm is loaded, can I programmatically change its modality? (Something in the dialog obviously is.)
4) If not, how can I programmatically return the focus to the UserForm?
The code that opens the dialog is located in a Class Module:
' •g_ImageEvents_Click Class Event Handler•
' Purpose: Set picture for selected image.
Private Sub g_ImageEvents_Click()
'
' Object variables:
' imgMe = Control to be edited.
Dim imgMe As Image
' Set imgMe to selected control.
Set imgMe = frmGraphicInsert.Controls("imgPicture" & g_ctrlIndex)
' Display wdDialogInsertPicture dialog box to select picture.
On Error GoTo HandleErr
With Dialogs(wdDialogInsertPicture)
.Display
If .Name = "" Then Exit Sub
' Load picture; change ControlTipText; update g_strAryGraphics.
imgMe.Picture = LoadPicture(.Name)
imgMe.ControlTipText = "Click to Change Picture"
g_strAryGraphics(g_ctrlIndex, 0) = .Name
End With
' Repaint frmGraphicInsert.
frmGraphicInsert.Repaint
HandleErr:
Exit Sub
End Sub
Clicking an image on the UserForm opens the wdDialogInsertPicture built-in dialog (dialogs collection). When this happens, the UserForm mysteriously becomes modeless and the document window becomes active (ie. the UserForm loses focus).
1) Why does this happen?
2) Is there a workaround?
3) Once a UserForm is loaded, can I programmatically change its modality? (Something in the dialog obviously is.)
4) If not, how can I programmatically return the focus to the UserForm?
The code that opens the dialog is located in a Class Module:
' •g_ImageEvents_Click Class Event Handler•
' Purpose: Set picture for selected image.
Private Sub g_ImageEvents_Click()
'
' Object variables:
' imgMe = Control to be edited.
Dim imgMe As Image
' Set imgMe to selected control.
Set imgMe = frmGraphicInsert.Controls("imgPicture" & g_ctrlIndex)
' Display wdDialogInsertPicture dialog box to select picture.
On Error GoTo HandleErr
With Dialogs(wdDialogInsertPicture)
.Display
If .Name = "" Then Exit Sub
' Load picture; change ControlTipText; update g_strAryGraphics.
imgMe.Picture = LoadPicture(.Name)
imgMe.ControlTipText = "Click to Change Picture"
g_strAryGraphics(g_ctrlIndex, 0) = .Name
End With
' Repaint frmGraphicInsert.
frmGraphicInsert.Repaint
HandleErr:
Exit Sub
End Sub