Allowing word document to be edited whilst userform is active

G

Ganeth

Here's a poser...

THE SITUATION: I have a userform that allows for searching and replacing of text in all open documents. Works just fine. You enter the text to be searched for in one text field, the replace text in another, click OK and off it goes. The code hides the form, cycles through all open word documents, performs the operation on each one, returns to the document which was active when the userform was invoked, queries if the user would like to generate a log file of the changes, and then sets the form to visible again for the user to enter more text to be changed, if he or she so wishes

THE PROBLEM: What I'd like to do, however, is allow the user to select text from the currently active document WITHOUT having to de-activate the userform: in exactly the same way that Word's built in find and replace form works. To specify, I'd like my users to be able to click on the currently active document, (have the form temporarily lose focus while the user selects and copies some text into the clipboard), and then allow the user to click the userform, (set the focus to the form again), and paste the text into the find textbox.

C'est possible

Dherai dhanyabaad (thank you very much) in advance for your assistance

Ganeth
 
D

Doug Robbins - Word MVP

If you are using Word 2000 or later, you can show the form as modeless using

Dim myform As UserForm1
Set myform = New UserForm1
myform.Show 0

By design, in Word97, userforms were always modal, but I seem to recall that
there was a bug which could be taken advantage of to get them to appear
modeless. A search in the word.vba.userforms group on Google would probably
turn it up.

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
Ganeth said:
Here's a poser...

THE SITUATION: I have a userform that allows for searching and replacing
of text in all open documents. Works just fine. You enter the text to be
searched for in one text field, the replace text in another, click OK and
off it goes. The code hides the form, cycles through all open word
documents, performs the operation on each one, returns to the document which
was active when the userform was invoked, queries if the user would like to
generate a log file of the changes, and then sets the form to visible again
for the user to enter more text to be changed, if he or she so wishes.
THE PROBLEM: What I'd like to do, however, is allow the user to select
text from the currently active document WITHOUT having to de-activate the
userform: in exactly the same way that Word's built in find and replace form
works. To specify, I'd like my users to be able to click on the currently
active document, (have the form temporarily lose focus while the user
selects and copies some text into the clipboard), and then allow the user to
click the userform, (set the focus to the form again), and paste the text
into the find textbox.
 
M

Murdoch

Hi

You've probably sorted this by now but in case not ...

In Word 2003 you can show a userform as modeless (which is what you need)
with eg MyForm.Show vbModeless

I've used the "feature" Doug Robbins mentions for Word 97 though I forget
whether I found it in a newsgroup or on www.mvps.org . The code I've got now
is:

Public Declare Sub SetActiveWindow Lib "User32.dll" (ByVal hWnd As Long)
....
SendKeys ("{ESC}")
Dialogs(wdDialogFileSaveAs).Display
' use next line instead of the above two when sendkeys does not work, but
it's a little slower:
' Dialogs(wdDialogFileOpen).Display (1)
SetActiveWindow (hForm) ' otherwise your form may not now be active
....

HTH and apologies to the genius who should really get the credit for
forgetting who they are!



Ganeth said:
Here's a poser...

THE SITUATION: I have a userform that allows for searching and replacing
of text in all open documents. Works just fine. You enter the text to be
searched for in one text field, the replace text in another, click OK and
off it goes. The code hides the form, cycles through all open word
documents, performs the operation on each one, returns to the document which
was active when the userform was invoked, queries if the user would like to
generate a log file of the changes, and then sets the form to visible again
for the user to enter more text to be changed, if he or she so wishes.
THE PROBLEM: What I'd like to do, however, is allow the user to select
text from the currently active document WITHOUT having to de-activate the
userform: in exactly the same way that Word's built in find and replace form
works. To specify, I'd like my users to be able to click on the currently
active document, (have the form temporarily lose focus while the user
selects and copies some text into the clipboard), and then allow the user to
click the userform, (set the focus to the form again), and paste the text
into the find textbox.
 

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