BertusX
03-04-2013, 05:29 AM
Hi everyone, I'm new to the forum, searched the archives but no answer found to this case:
Upon printing a document, I need to temporarily hide any shape in the header of a specific section.
I have a document, containing 4 sections.
section 1 2 and 3 are DIN A4 papersize, portrait oriented
section 4 is landscape oriented
section 1-3 will be printed on company paper, so the logo image in the headers 1-3 must be hidden, while in section 4 it must be shown
So, on 3 sections, the company logo needs to be hidden while printing, and shown again afterwards. Let's worry about the "shown again" part later.
Here's my code:
Sub PrintPreviewAndPrint()
Dim sc As Section
Dim booShow As Boolean
Dim sp As Shape
For Each sc In ActiveDocument.Sections
With sc.PageSetup
booShow = Not (.Orientation = wdOrientPortrait And .PaperSize = wdPaperA4)
End With
For Each sp In sc.Headers(wdHeaderFooterPrimary).Shapes
sp.Visible = booShow
Next sp
Next sc
End Sub
So the code loops through sections. Come section 1, images in all section headers are hidden. Same goes for sections 2 and 3. Come section 4 images in all sections are shown again. I'd expect that in the end, images in first 3 sections are hidden, and in section 4 is displayed.
Could anybody please tell me what I'm doing wrong here?
Second: how do I get to display all images again after the document was printed?
Please help me out.
Many thanks
Bart
Upon printing a document, I need to temporarily hide any shape in the header of a specific section.
I have a document, containing 4 sections.
section 1 2 and 3 are DIN A4 papersize, portrait oriented
section 4 is landscape oriented
section 1-3 will be printed on company paper, so the logo image in the headers 1-3 must be hidden, while in section 4 it must be shown
So, on 3 sections, the company logo needs to be hidden while printing, and shown again afterwards. Let's worry about the "shown again" part later.
Here's my code:
Sub PrintPreviewAndPrint()
Dim sc As Section
Dim booShow As Boolean
Dim sp As Shape
For Each sc In ActiveDocument.Sections
With sc.PageSetup
booShow = Not (.Orientation = wdOrientPortrait And .PaperSize = wdPaperA4)
End With
For Each sp In sc.Headers(wdHeaderFooterPrimary).Shapes
sp.Visible = booShow
Next sp
Next sc
End Sub
So the code loops through sections. Come section 1, images in all section headers are hidden. Same goes for sections 2 and 3. Come section 4 images in all sections are shown again. I'd expect that in the end, images in first 3 sections are hidden, and in section 4 is displayed.
Could anybody please tell me what I'm doing wrong here?
Second: how do I get to display all images again after the document was printed?
Please help me out.
Many thanks
Bart