Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-02-2015, 09:04 PM
LaurieH LaurieH is offline Hide Command Buttons Windows 7 64bit Hide Command Buttons Office 2007
Novice
Hide Command Buttons
 
Join Date: Jan 2015
Location: Perth, Australia
Posts: 6
LaurieH is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 01-02-2015, 11:09 PM
gmayor's Avatar
gmayor gmayor is offline Hide Command Buttons Windows 7 64bit Hide Command Buttons Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,105
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

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
Reply With Quote
  #3  
Old 01-02-2015, 11:23 PM
LaurieH LaurieH is offline Hide Command Buttons Windows 7 64bit Hide Command Buttons Office 2007
Novice
Hide Command Buttons
 
Join Date: Jan 2015
Location: Perth, Australia
Posts: 6
LaurieH is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 01-03-2015, 02:28 AM
gmayor's Avatar
gmayor gmayor is offline Hide Command Buttons Windows 7 64bit Hide Command Buttons Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,105
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

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
Reply With Quote
  #5  
Old 01-03-2015, 03:40 AM
LaurieH LaurieH is offline Hide Command Buttons Windows 7 64bit Hide Command Buttons Office 2007
Novice
Hide Command Buttons
 
Join Date: Jan 2015
Location: Perth, Australia
Posts: 6
LaurieH is on a distinguished road
Default

One textbox only, and it sits in front of text, I guess that is what you call "floating."
Reply With Quote
  #6  
Old 01-03-2015, 04:52 AM
gmayor's Avatar
gmayor gmayor is offline Hide Command Buttons Windows 7 64bit Hide Command Buttons Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,105
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

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).
Attached Files
File Type: docm Example.docm (37.6 KB, 45 views)
__________________
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
  #7  
Old 01-03-2015, 05:43 PM
LaurieH LaurieH is offline Hide Command Buttons Windows 7 64bit Hide Command Buttons Office 2007
Novice
Hide Command Buttons
 
Join Date: Jan 2015
Location: Perth, Australia
Posts: 6
LaurieH is on a distinguished road
Default

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.
Attached Files
File Type: docm Timesheet - no links.docm (296.9 KB, 16 views)
Reply With Quote
  #8  
Old 01-04-2015, 12:02 AM
gmayor's Avatar
gmayor gmayor is offline Hide Command Buttons Windows 7 64bit Hide Command Buttons Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,105
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

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?
Attached Files
File Type: docm Timesheet - no links.docm (305.9 KB, 26 views)
__________________
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
  #9  
Old 01-04-2015, 04:25 AM
LaurieH LaurieH is offline Hide Command Buttons Windows 7 64bit Hide Command Buttons Office 2007
Novice
Hide Command Buttons
 
Join Date: Jan 2015
Location: Perth, Australia
Posts: 6
LaurieH is on a distinguished road
Default

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?
Reply With Quote
  #10  
Old 01-04-2015, 05:14 AM
gmayor's Avatar
gmayor gmayor is offline Hide Command Buttons Windows 7 64bit Hide Command Buttons Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,105
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

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
Reply With Quote
  #11  
Old 01-04-2015, 06:08 AM
LaurieH LaurieH is offline Hide Command Buttons Windows 7 64bit Hide Command Buttons Office 2007
Novice
Hide Command Buttons
 
Join Date: Jan 2015
Location: Perth, Australia
Posts: 6
LaurieH is on a distinguished road
Default

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
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Hiding Command Buttons before PDF ksigcajun Word VBA 3 05-07-2014 05:31 AM
Hide Command Buttons 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

Other Forums: Access Forums

All times are GMT -7. The time now is 04:24 PM.


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