Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-24-2015, 07:40 AM
spc94 spc94 is offline Executing a userform with a command button Windows 7 64bit Executing a userform with a command button Office 2010 64bit
Novice
Executing a userform with a command button
 
Join Date: Jun 2015
Location: Ohio, USA
Posts: 8
spc94 is on a distinguished road
Default Executing a userform with a command button

I have created a user form that has multiple check boxes. I want to be able to execute the check boxes selected by clicking a command button that will close the user form. Here is the code I have for the check boxes which I tested an works.

Sub CheckBox1_Click()
Unload Me
ChangeFileOpenDirectory _"X:\sconner\CCD Damage Mechanisms\Data Transfer Practice\"
Documents.Open FileName:= _
"X:\sconner\CCD Damage Mechanisms\Data Transfer Practice\Mechanism Transfer Practice.docx" _
, ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _


PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
wdOpenFormatAuto, XMLTransform:=""
Selection.WholeStory
Selection.Copy
ActiveWindow.Close
Selection.PasteAndFormat (wdFormatOriginalFormatting)
End Sub
Reply With Quote
  #2  
Old 06-24-2015, 02:59 PM
macropod's Avatar
macropod macropod is offline Executing a userform with a command button Windows 7 64bit Executing a userform with a command button Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Without knowing what you want to execute, it's impossible to give any advice. However, unloading the form as your post indicates before executing its code is liable to result in the code not being executed.

Also, you don't need to change folders via ChangeFileOpenDirectory. You can open the file explicitly. Nor do you need to copy & paste. Try, for example:
Code:
Sub CheckBox1_Click()
Dim DocSrc As Document, DocTgt As Document
Const StrFld As String = "X:\sconner\CCD Damage Mechanisms\Data Transfer Practice\"
Set DocTgt = ActiveDocument
Set DocSrc = Documents.Open(FileName:=StrFld & "Mechanism Transfer Practice.docx", _
  ReadOnly:=False, AddToRecentFiles:=False)
DocTgt.Range.FormattedText = DocSrc.Range.FormattedText
DocSrc.Close
Unload Me
End Sub
PS: When posting code, please use the code tags, inserted via the # button on the posting menu.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 06-24-2015, 10:08 PM
gmayor's Avatar
gmayor gmayor is offline Executing a userform with a command button Windows 7 64bit Executing a userform with a command button 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

This seems to relate to your other post?
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply

Tags
command button, macros, userforms

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with a Command Button dkohnken Word VBA 5 03-18-2015 10:13 PM
VBA Code in a UserForm module to delete a Command Button which opens the userform Simoninparis Word VBA 2 09-21-2014 03:50 AM
Command button to show userform suddenly stopped working jpb103 Word VBA 0 05-22-2014 06:05 AM
Word doc bug when closing from userform command button click macro Joe Patrick Word 1 07-05-2011 08:53 PM
Executing a userform with a command button Command Button cksm4 Word VBA 7 02-27-2011 08:47 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:46 AM.


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