#1
|
|||
|
|||
Hide Command Buttons
Hi, by asking this question it's obvious my VBA skills are lacking, I've searched the internet and can't find a working solution, so many links take me to excel. Here's my problem, I have a form, with two (2) command buttons, one is to print the document, when this button is pressed I want both buttons to be hidden so that they do not print, something along the lines of " CommandButton22.Visible = False" and after printing I want buttons visible, along the lines of " CommandButton22.Visible = True." I am using Word 2007. If it's easier in Word 2013 then I will upgrade. Thanks for any help. Regards Laurie |
#2
|
||||
|
||||
Where did you search? - See http://word.mvps.org/faqs/tblsfldsfm...rintButton.htm
An alternative suggestion would be to put your buttons on the ribbon. If you have a ribbon tab in the document/template and set it before the Home tab, it will be the active tab when that document is open. Editing the tab is another skill that you will find useful. See http://gregmaxey.com/word_tip_pages/...bbon_main.html
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
Hi Graham, yes, I saw that site, gave it a try but it didn't work, I'm not sure, but suspect it might have something to do with the textbox index number but I don't know where/how to find the correct number.
|
#4
|
||||
|
||||
Do you have more than one text box in the document?
Is the text box inserted in-line with text or 'floating'.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#5
|
|||
|
|||
One textbox only, and it sits in front of text, I guess that is what you call "floating."
|
#6
|
||||
|
||||
In that case it should work as quoted in the web page (albeit you need to change the code to reflect the correct command button).
See the attached example (you will have to allow the macro to run the code). Click the print button and see what happens in the printout. (You won't see a change on screen).
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#7
|
|||
|
|||
Strangely, your example works, but mine doesn't, so have attached a copy of my document. AS you will see, my code, for command button 22, is, I hope, the same but it still prints the text box and buttons.
|
#8
|
||||
|
||||
It is not so strange, your document makes much use of shapes, and the shape in question is Shape(3).
I have fixed the code so that both buttons work as intended. I have added a couple of modules to supply the ancillary functions, one of which assumes you have Outlook to submit the sheet (It won't send the message while testing). The other ensures the named folder is present and prevents overwriting existing files of the same name. The form would not appear to be of much use while you use an object as the table instead of a real table, but I think have provided enough information for you to continue should you want to go that route?
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#9
|
|||
|
|||
Thanks, for your help, Graham, the original document was not created by me, I'm using it to learn VBA, I have "linked" the tables to my excel sheet, which performs the calculations. One question, is there a way to find the "shapes" number?
|
#10
|
||||
|
||||
OK, a link is one way to do it. You will find the additional functions I threw in useful in a variety of VBA projects.
As a generalisation, I would avoid using text boxes to format documents (you will note I removed one and replaced it with a bookmark for the insertion of text directly into the document). Text boxes just complicate things unnecessarily. This method of hiding buttons is a notable exception. If you want boxes, use table cells or frames, as they are easier to process, being in the text 'layer' of the document. Check VBA Editor > Tools > Options > Editor > Require Variable Declaration as this will help point out errors in your coding. It's a good idea to start on your VBA path by declaring all variables, and this will insist on it. You can find the shapes index with a macro e.g. Code:
Sub GetShapeIndex() Dim i As Long For i = 1 To ActiveDocument.Shapes.Count ActiveDocument.Shapes(i).Select Application.ScreenRefresh MsgBox "Shapes(" & i & ") selected" Next i lbl_Exit: Exit Sub End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#11
|
|||
|
|||
That macro is just what I needed, I would have thought Microsoft would have a feature like that included. Thanks again for your patience and help. This programming, although at times frustrating, is good brain exercise
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Hiding Command Buttons before PDF | ksigcajun | Word VBA | 3 | 05-07-2014 05:31 AM |
Command buttons on slidemaster | chcope | PowerPoint | 2 | 06-13-2013 04:30 PM |
Command Buttons | lorenambrose | Word | 0 | 10-06-2011 11:55 AM |
command buttons | ronf | Excel | 0 | 04-28-2006 08:32 AM |
command buttons | ronf | Excel | 0 | 12-03-2005 06:26 AM |