Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2006

Tip: Looking for answers? Try searching our database.

[msword/vba] Problem with showing/hiding shapes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dwergkees - 19 Apr 2006 15:46 GMT
Got a strange problem:

A document has a corporate logo, which doesn't need to be printed on
the clients pc (as he has preprinted paper). The logo does need to be
printed other computers (when client for example mails a document).

My solution is as follows: intercept the print commands on clients pc,
hide the logo before printing, show it again when ready.

Code is on bottom of page. The strange problem is: When I open the
document and try to print, it doesn't work the first time, but it does
work the second. Both times the sub is called and processed with no
errors, as both times I get the messageBoxes(!). Also, it does work
directly when the VBA window is open.

Any ideas?

Code:

Sub FilePrint()
   'To intercept File > Print and CTRL-P
   toggleLogos

End Sub

Sub FilePrintDefault()
   'To intercept the Standard toolbar button
   toggleLogos True

End Sub

Sub toggleLogos(Optional toolbar As Boolean = False)

   Dim logo As Shape, headerLogo As Shape

   ' fetch prenamed shapes
   Set logo = Application.ActiveDocument.Shapes("Logo")
   Set headerLogo =
Application.ActiveDocument.Sections.Item(1).Headers.Item(wdHeaderFooterPrimary).Shapes("LogoHeader")

   ' Just to check if this sub is called properly
   MsgBox logo.Name
   MsgBox headerLogo.Name

   ' hide shapes
   logo.Visible = msoFalse
   headerLogo.Visible = msoFalse

   ' show print dialog or just spit it out
   If toolbar Then
       ActiveDocument.PrintOut
   Else
       Dialogs(wdDialogFilePrint).Show
   End If

   ' show shapes
   logo.Visible = msoTrue
   headerLogo.Visible = msoTrue
   
End Sub
Jean-Guy Marcil - 19 Apr 2006 21:40 GMT
dwergkees was telling us:
dwergkees nous racontait que :

> Got a strange problem:
>
[quoted text clipped - 10 lines]
> errors, as both times I get the messageBoxes(!). Also, it does work
> directly when the VBA window is open.

So it does not work the first time you call the macro, but every time after
that it works, until you close the document. Right?

What if you change
   logo.Visible = msoFalse
   headerLogo.Visible = msoFalse
to
   logo.Visible = False
   headerLogo.Visible = False

and
   logo.Visible = msoTrue
   headerLogo.Visible = msoTrue
to
   logo.Visible = True
   headerLogo.Visible = True
???

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org 

dwergkees - 20 Apr 2006 08:09 GMT
>What if you change
>   logo.Visible = msoFalse
>    headerLogo.Visible = msoFalse
>to
>    logo.Visible = False
>    headerLogo.Visible = False

already tried and tested, just as error trapping on or off (on error
resume ...)
walking through the code doesn't help, as it always work when the vba
window is open :(
Jean-Guy Marcil - 20 Apr 2006 18:49 GMT
dwergkees was telling us:
dwergkees nous racontait que :

>> What if you change
>>   logo.Visible = msoFalse
[quoted text clipped - 7 lines]
> walking through the code doesn't help, as it always work when the vba
> window is open :(

Well, I am not sure what to write at this point. The code you posted seemed
OK.
(
Except maybe that
   Set headerLogo =
Application.ActiveDocument.Sections.Item(1).Headers.Item(wdHeaderFooterPrimary).Shapes("LogoHeader")
was a little "overkill," this would have worked as well:
   Set headerLogo =
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes("LogoHeader")
)

So I am not sure I can help, except if you do not mind me looking at your
document. Un-mangled my email address in my signature if you want me to take
a quick look at it.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org 

dwergkees - 20 Apr 2006 20:42 GMT
> Well, I am not sure what to write at this point. The code you posted seemed
> OK.

Yeah, that's my problem, it all * seems * OK, it's beginning to look
like a vba/word bug by now :)

Anyway, i mailed you a document containing both code and images (real
app has code in normal.dot) wich reproduces the exact problem. Just
press File > Print, then Cancel and then repeat the procedure. the
first time the images won't hide (but the msgboxes appear), the second
time the images will hide. (at least on the two pc's i tested on).

TIA!

Wilco Menge (aka Dwergkees)
Jean-Guy Marcil - 20 Apr 2006 21:06 GMT
dwergkees was telling us:
dwergkees nous racontait que :

>> Well, I am not sure what to write at this point. The code you posted
>> seemed OK.
[quoted text clipped - 11 lines]
>
> Wilco Menge (aka Dwergkees)

Sorry, but...
Here is what I did:

1. I open the document you sent and saw the 2 logos
2. I hit CTRL-P
3. Right away I noticed the 2 logos become invisible
4. The print dialog appeared
5. I hit Cancel
6. The logos became visible again
7. The 2 message boxes appeared

Then, as you mentioned when you wrote to me directly, just in case, I
transferred the code to Normal.dot and tried again.
Same result.

So... what is going on at your end of things?

One thing I forgot to ask from the get go... What Office version are you
using?
That might make a difference.
I tested your document on Office 2003 SP2.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org 

dwergkees - 21 Apr 2006 22:48 GMT
at your side it works as expected, so it seems to be my setup. my
setup: winXP sp2, office 2003 sp2 (the same as yours it seems)

the thing that goes wrong at my end is point 3. the logo's wont go
invisible. when i repeat the steps it does. seems to me like some sort
of bug, i am not going to track anymore but blame it on ms instead :)

thanks for looking into it!

dwergkees
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.