|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
VBA Code in a UserForm module to delete a Command Button which opens the userform
Hello all,
I hope the title says (nearly) everything. In MSWord, I am trying to develop a system in which: 1 User opens a document (document is write protected) 2 User Clicks on a "Start" button on the doc 3 The "Start" button opens a Userform into which users input data in required formats 4 The UserForm puts all the data in the appropriate place on the main document 5 The document is saved as "input1_input2_input3.doc" - inputs from UserForm. I can get all the above to work. But.... Problem: Between 4 and 5, or after 5, I would like to get the "Start" command button to be deleted. I have tried recording a macro and pasting the code into the UserForm module code. No matter whether I use ThisDocument or ActiveDocument, it does not work. It appears that it wants to act on the UserForm. Do I need (somehow) to set the focus to the main document? I am sure this can be done but for the moment it is beyond me. Any help would be most welcome and much appreciated. Many thanks, Simon BTW: Because some of my colleagues use antique PCs, I am obliged to save it as 97/2003 format. |
#2
|
||||
|
||||
Is there a reason for having the command button (presumably an ActiveX button) and not starting the userform automatically instead? The code you'd use for deleting the command button would be something like:
ThisDocument.CommandButton1.Delete but you'll have problems deleting the command button while it's running a macro - which it continues to do until you unload your userform. Alternatively, have you considered using a MACROBUTTON field to start your userform instead of the command button? Such a field might be coded as: {MACROBUTTON UserformLoad Click Here} and Drive a UserformLoad macro coded as: Code:
Sub UserformLoad() ActiveDocument.Fields(1).Result.Delete UserForm1.Show End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Logic failed me
Paul,
Thanks for your rapid reply. Yes, it is logical that a calling button cannot delete itself. Sometimes in life one needs someone to give a flash a the blindingly obvious; you did that to me, thanks. There is no reason why the user needs to see a form with which they are already (or soon will be) familiar. Now, the form opens up on opening the doc and everything is right with the world. All the best, Simon |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Command button to show userform suddenly stopped working | jpb103 | Word VBA | 0 | 05-22-2014 06:05 AM |
UserForm Search, delete issues | johndough | Excel Programming | 3 | 05-11-2014 11:44 AM |
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 |
Userform Code not quite right - help please | vbanovice | Word VBA | 1 | 09-29-2013 09:20 PM |
Word doc bug when closing from userform command button click macro | Joe Patrick | Word | 1 | 07-05-2011 08:53 PM |