#1
|
|||
|
|||
Change focus from userForm back to word document to see results.
Change focus from userForm back to word document to see results. I am using Word 2010. I am trying to create a userForm with several buttons that will execute small programs or macros on my current document. I can create and start my userForm, assign code to buttons and they work BUT I can't see the results in the document until I exit. What I am looking for is a way to execute a SUB from my userForm then see the results in my document immediately. I don't care where the focus ends up after that. Is this doable? Thanks |
#2
|
||||
|
||||
Whether the macro results will be shown in real time rather depends on the macro code and what it is supposed to do. For example, add a DocVariable field to the document
{ DOCVARIABLE "varText" } Create a macro Sub Test1() Dim oFld As Field ActiveDocument.Variables("varText").Value = "This is text" For Each oFld In ActiveDocument.Fields If oFld.Type = wdFieldDocVariable Then If InStr(1, oFld.Code.Text, "varText") > 0 Then oFld.Update Exit For End If Next oFld End Sub and run that from a button on the userform Private Sub CommandButton2_Click() Call Test1 End Sub The docvariable field will be updated in real time. Similarly you can add the content of a text box to a docvariable and associated field Private Sub TextBox1_Change() Dim oFld As Field ActiveDocument.Variables("varTextBox1").Value = TextBox1.Text For Each oFld In ActiveDocument.Fields If oFld.Type = wdFieldDocVariable Then If InStr(1, oFld.Code.Text, "varTextBox1") > 0 Then oFld.Update Exit For End If Next oFld End Sub Graham Mayor - MS-MVP (Word) www.gmayor.com |
Tags |
focus userform document |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Is it possible to take an input from a UserForm in one document to a UserForm in a do | BoringDavid | Word VBA | 5 | 05-09-2014 09:08 AM |
how keep word document highlighted when switching focus to another application? | dylansmith | Word | 4 | 05-08-2013 01:21 AM |
Show userform without losing document focus? Or other method to get a graphic to pop? | AlexR | Word VBA | 7 | 03-31-2013 12:17 PM |
How to link userform to another word document | SaneMan | Word VBA | 5 | 10-14-2011 05:12 AM |
Setting focus to specific word document from UserForm | SaneMan | Word VBA | 5 | 04-01-2011 03:11 PM |