Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 08-11-2014, 05:00 AM
gmayor's Avatar
gmayor gmayor is offline Change focus from userForm back to word document to see results. Windows 7 64bit Change focus from userForm back to word document to see results. Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,142
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
 

Tags
focus userform document



Similar Threads
Thread Thread Starter Forum Replies Last Post
Change focus from userForm back to word document to see results. 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
Change focus from userForm back to word document to see results. how keep word document highlighted when switching focus to another application? dylansmith Word 4 05-08-2013 01:21 AM
Change focus from userForm back to word document to see results. 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
Change focus from userForm back to word document to see results. How to link userform to another word document SaneMan Word VBA 5 10-14-2011 05:12 AM
Change focus from userForm back to word document to see results. Setting focus to specific word document from UserForm SaneMan Word VBA 5 04-01-2011 03:11 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:21 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft