Re: HidingMacroButtonInPrintout
- From: mike <mike@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 29 Jun 2009 17:13:01 -0700
Jay, thanks for hanging in there.
Read you response and changed lanquage to:
Private Sub CommandButton2_Click()
With ActiveDocument
..Shapes(12).Visible = msoFalse
..Shapes(13).Visible = msoFalse
..PrintOut Range:=wdPrintRangeOfPages, Pages:="3"
..Shapes(12).Visible = msoTrue
..Shapes(13).Visible = msoTrue
End With
End Sub
Now I receive "the index into the specfic collection is out of bounds"
statement
when I debug.--
Michael
"Jay Freedman" wrote:
Look carefully at what I posted. You left out the "With ActiveDocument" and.
"End With" lines, and you left in the unwanted "ActiveDocument" in the
PrintOut line.
The reason for the "With ActiveDocument" line is to provide the "reference"
for each line that starts with a dot. The dot means "member of", as in "the
Shapes collection is a member of the ActiveDocument object". The "With"
statement is a shortcut -- it says "wherever you see a dot without an
object's name in front of it, use the object in this With statement". And
whenever you use a With statement, you must have an End With statement to
match it.
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
mike wrote:
Jay
Thanks for your help, When I used your suggestions in the below
stated lines
private Sub CommandButton2_Click()
.Shapes(12).Visible = msoFalse
.Shapes(13).Visible = msoFalse
ActiveDocument.PrintOut Range:=wdPrintRangeOfPages, Pages:="3",
Copies:=1 .Shapes(12).Visible = msoTrue
.Shapes(13).Visible = msoTrue
End Sub
I receive a "Invalid or unqualified reference" statement
Again command buttons 12 and 13 are on page 3.
Command button2 is on page 1 which is an index page with many buttons.
Thanks again for your help
In the sample code I showed (repeated here for reference):
Private Sub CommandButton1_Click()
With ActiveDocument
.Shapes(1).Visible = msoFalse
.PrintOut Range:=wdPrintRangeOfPages, Pages:="1"
.Shapes(1).Visible = msoTrue
End With
End Sub
The number in the first line in "CommandButton1_Click" determines
which button causes the macro to run. In your situation, you need it
to say "CommandButton2_Click".
The number in the ".Shapes(1).Visible" lines determine which button
is being hidden and unhidden. Since you want to hide/unhide two
buttons, you need two of each line:
.Shapes(12).Visible = msoFalse
.Shapes(13).Visible = msoFalse
before the .PrintOut statement and then
.Shapes(12).Visible = msoTrue
.Shapes(13).Visible = msoTrue
after it.
The number in the .PrintOut line, after Pages:=, determines what page
to print, so you need Pages:="3" there.
On Fri, 26 Jun 2009 17:46:01 -0700, mike
<mike@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Jay
Almost there, I get what you are saying.
Here is what some further info that I hope you can help.
Page 1 has 20 command buttons.
Command button 2 print out page 3. Page 3 has 2 command button
named 12 and 13. How can I modify what you sent so that when command
button 2 is clicked, it will print out page 3 and hide button 12
and 13.
Command buttons 12 and 13, let the operator either print out page 3
or return to page 1. They are navigational aides in the document.
thanks for your help.
--
Michael
"Jay Freedman" wrote:
I assumed -- which I should never do -- that you had some idea of
how the code that you posted does its work. Sorry... here's the
novice version.
First, you need to know about the Shapes collection. It's a list of
all the non-inline graphics objects in the document. Each of the
command buttons is a Shape object in that collection, and there
might be others (pictures, drawing objects, and text boxes are
also Shape objects). Each Shape object in the collection has a
number, called its index; the first Shape in the collection is
referred to as Shapes(1), the next as Shapes(2), and so on.
If the only Shape objects in the document are the command buttons,
then probably CommandButton1 is Shapes(1) and so on. If there are
other Shape objects, you'll have to experiment a bit to find the
right indexes to point to the command buttons.
The other thing you ran into is that the code in the mvps.org
article just has a PrintOut command with no extra information, and
that prints the entire document. The version in your code, with
the Range and Pages information, limits the printing to one page.
The last bit you need to notice is that there is a separate macro
procedure for each command button, and it contains a different
number in the Pages item of the PrintOut command. That's how each
button "knows" which page it's on. (As an aside, the "Copies:=1"
part isn't necessary because Word will use that value even if you
omit it.)
Putting these things together, the code for the first command
button will be -- assuming that CommandButton1 really is Shapes(1)
--
Private Sub CommandButton1_Click()
With ActiveDocument
.Shapes(1).Visible = msoFalse
.PrintOut Range:=wdPrintRangeOfPages, Pages:="1"
.Shapes(1).Visible = msoTrue
End With
End Sub"
and each of the others will be the same except for replacing the
number 1 in four places with the proper number for that command
button.
On Wed, 24 Jun 2009 17:01:01 -0700, mike
<mike@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Jay
Not working.
When I paste these directions, first I get the whole document
to print instead of just page 6
And the print command button shows on the page. What position
in the below stated code do I paste the information code that you
refered to.
Thanks for responding
--
Michael
"Jay Freedman" wrote:
See http://word.mvps.org/FAQs/TblsFldsFms/HidePrintButton.htm
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
On Tue, 23 Jun 2009 18:07:01 -0700, mike
<mike@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
I have a word document that has a macro print page button on
each page. The print code looks like
"Private Sub CommandButton5_Click()
ActiveDocument.PrintOut Range:=wdPrintRangeOfPages, _
Pages:="6", _
Copies:=1
End Sub"
How do you make a macro button embedded in a document not
appear in the document when printed?
If additional code is needed, where would this code be placed
in the above Segment?
Thanks for any help
Mike
- Follow-Ups:
- Re: HidingMacroButtonInPrintout
- From: Jay Freedman
- Re: HidingMacroButtonInPrintout
- References:
- Re: HidingMacroButtonInPrintout
- From: Jay Freedman
- Re: HidingMacroButtonInPrintout
- From: mike
- Re: HidingMacroButtonInPrintout
- From: Jay Freedman
- Re: HidingMacroButtonInPrintout
- From: mike
- Re: HidingMacroButtonInPrintout
- From: Jay Freedman
- Re: HidingMacroButtonInPrintout
- From: mike
- Re: HidingMacroButtonInPrintout
- From: Jay Freedman
- Re: HidingMacroButtonInPrintout
- Prev by Date: Re: Tables and text in a document
- Next by Date: Re: Programming Macro for Save As in Word 2003
- Previous by thread: Re: HidingMacroButtonInPrintout
- Next by thread: Re: HidingMacroButtonInPrintout
- Index(es):
Relevant Pages
|