N
NZ VBA Developer
Recently I posted a question about code hanging after displaying a built-in
dialog that got no response. I now have some more information that might help.
It seems that the code only hangs if the built-in dialog allows the entry of
text for insertion into the document and only if text is actually entered
manually. The dialog in question in my previous post was the 'Caption'
dialog. I've been working with the 'Envelopes and Labels' dialog recently and
ran into the same problem - but only intermittently. So I had a look at when
the code hung and when it didn't and discovered that if I fed the address
information to the 'Envelopes and Labels' dialog programmatically (e.g.
populated it with values from a UserForm), everything was fine. However, if I
added or modified the address information manually - even after populating it
originally from the UserForm - the code hung.
I reckon this is some sort of bug in Word, and I don't for a minute imagine
it's anything under my control. If I manually enter text into a dialog that's
displayed through code, the code is going to hang. I'm just wondering: has
anyone encounterd this problem previously and if you have, have you been able
to find a workaround - or at least a way to 'unhang' the code?
The problem is easy enough to recreate. Just create a UserForm with a single
TextBox and a CommandButton, then add the following code to the click event
for the button:
Private Sub CommandButton1_Click()
UserForm1.Hide
Dialogs(wdDialogToolsCreateEnvelope).AddrText = TextBox1.Value
Unload UserForm1
End Sub
This should display the built-in 'Envelopes and Labels' dialog box with the
value from the TextBox on the UserForm displayed in the 'Delivery address'
field. If you just add the envelope to the document, the code should continue
to run, but if you change the address info manually, it will hang. The code
can't be reset or even modified until you close and restart Word.
--
Cheers!
The Kiwi Koder
Please note: Uninvited email contact will be marked as SPAM and ignored -
unless you want to hire me. ;-)
dialog that got no response. I now have some more information that might help.
It seems that the code only hangs if the built-in dialog allows the entry of
text for insertion into the document and only if text is actually entered
manually. The dialog in question in my previous post was the 'Caption'
dialog. I've been working with the 'Envelopes and Labels' dialog recently and
ran into the same problem - but only intermittently. So I had a look at when
the code hung and when it didn't and discovered that if I fed the address
information to the 'Envelopes and Labels' dialog programmatically (e.g.
populated it with values from a UserForm), everything was fine. However, if I
added or modified the address information manually - even after populating it
originally from the UserForm - the code hung.
I reckon this is some sort of bug in Word, and I don't for a minute imagine
it's anything under my control. If I manually enter text into a dialog that's
displayed through code, the code is going to hang. I'm just wondering: has
anyone encounterd this problem previously and if you have, have you been able
to find a workaround - or at least a way to 'unhang' the code?
The problem is easy enough to recreate. Just create a UserForm with a single
TextBox and a CommandButton, then add the following code to the click event
for the button:
Private Sub CommandButton1_Click()
UserForm1.Hide
Dialogs(wdDialogToolsCreateEnvelope).AddrText = TextBox1.Value
Unload UserForm1
End Sub
This should display the built-in 'Envelopes and Labels' dialog box with the
value from the TextBox on the UserForm displayed in the 'Delivery address'
field. If you just add the envelope to the document, the code should continue
to run, but if you change the address info manually, it will hang. The code
can't be reset or even modified until you close and restart Word.
--
Cheers!
The Kiwi Koder
Please note: Uninvited email contact will be marked as SPAM and ignored -
unless you want to hire me. ;-)