Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-03-2014, 02:06 PM
Hank Smith Hank Smith 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 64bit
Novice
Change focus from userForm back to word document to see results.
 
Join Date: Aug 2014
Posts: 1
Hank Smith is on a distinguished road
Arrow 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
Reply With Quote
  #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,101
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 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
Reply

Tags
focus userform document

Thread Tools
Display Modes


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 06:46 PM.


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