![]() |
#1
|
|||
|
|||
![]()
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 |
#2
|
||||
|
||||
![]()
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
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
||||
|
||||
![]()
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 |
![]() |
Tags |
command button, macros, userforms |
Thread Tools | |
Display Modes | |
|
![]() |
||||
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 |
![]() |
cksm4 | Word VBA | 7 | 02-27-2011 08:47 PM |