Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-21-2014, 01:31 AM
Simoninparis Simoninparis is offline VBA Code in a UserForm module to delete a Command Button which opens the userform Windows 7 64bit VBA Code in a UserForm module to delete a Command Button which opens the userform Office 2010 64bit
Novice
VBA Code in a UserForm module to delete a Command Button which opens the userform
 
Join Date: Feb 2012
Posts: 4
Simoninparis is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 09-21-2014, 02:30 AM
macropod's Avatar
macropod macropod is offline VBA Code in a UserForm module to delete a Command Button which opens the userform Windows 7 64bit VBA Code in a UserForm module to delete a Command Button which opens the userform Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,225
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

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]
Reply With Quote
  #3  
Old 09-21-2014, 03:50 AM
Simoninparis Simoninparis is offline VBA Code in a UserForm module to delete a Command Button which opens the userform Windows 7 64bit VBA Code in a UserForm module to delete a Command Button which opens the userform Office 2010 64bit
Novice
VBA Code in a UserForm module to delete a Command Button which opens the userform
 
Join Date: Feb 2012
Posts: 4
Simoninparis is on a distinguished road
Default 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
Reply With Quote
Reply

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
VBA Code in a UserForm module to delete a Command Button which opens the userform UserForm Search, delete issues johndough Excel Programming 3 05-11-2014 11:44 AM
VBA Code in a UserForm module to delete a Command Button which opens the userform 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

Other Forums: Access Forums

All times are GMT -7. The time now is 11:20 PM.


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