Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-08-2015, 07:39 AM
mhagi mhagi is offline selecting shape in header only Windows 7 64bit selecting shape in header only Office 2010 64bit
Novice
selecting shape in header only
 
Join Date: Oct 2015
Posts: 8
mhagi is on a distinguished road
Default selecting shape in header only

Hi,
i'm trying to count shapes in a specific Header only, i.e. how many shapes are in Primary Header of section 1 ( alt. how many shapes are in Primary footer of section 1). I have shapes in header and footer and want different actions for each. So I have to identify them separately.

activedocument.section(x).headers(wdheaderfooterpr imary).shapes.count

gives total number of all shapes in primary headersfooters.


I only want the number of shapes in Header and - ultimately - to do something with them.
How do I go about that?

Thanks in advance
Reply With Quote
  #2  
Old 10-08-2015, 05:10 PM
macropod's Avatar
macropod macropod is offline selecting shape in header only Windows 7 64bit selecting shape in header only Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Since shapes can have names, if you name one (or know the default name Word has allocated to it) you can reference it by that. Alternatively, you can loop through them using code like:
Code:
Dim i As Long
With ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary)
  For i = 1 To .Shapes.Count
    With .Shapes(i)
      'change a property
    End With
  Next
End With
The problem with looping through a shape collection or referencing them by index #, though, is that the position on-screen doesn't determine the index #; that is determined by where the shape is anchored and what other shapes are anchored at the same position.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 10-09-2015, 12:04 AM
mhagi mhagi is offline selecting shape in header only Windows 7 64bit selecting shape in header only Office 2010 64bit
Novice
selecting shape in header only
 
Join Date: Oct 2015
Posts: 8
mhagi is on a distinguished road
Default selecting shape in header only

Hi,

thanks for your answer. Could you give me a hint, how to address a shape anchored to a specific paragraph with a specific format.

Aim of the macro is
a) to insert Company logo in Header (and footer) if printing in pdf
b) delete/hide logos in Header and footer if printing on Company paper
and this thru all sections with different page layout and whatever.
And - there could be additional shapes if users include 3rd Party logos in documents and those not be deleted at all.

I could go thru all the shapes and identify my search object(s) by height or width, but was looking for an easier solution.

I'm not really THE vba expert and lazy as hell - always hoping WWW has a solution i can understand ("dim objects" are the high of my know how, so nothing above that!).

And I hoped it would be possible to only work with headers or footers. Now I have to look at both and I'm afraid, this will slow the macro down a lot.

Thanks nonetheless
Reply With Quote
  #4  
Old 10-09-2015, 12:17 AM
macropod's Avatar
macropod macropod is offline selecting shape in header only Windows 7 64bit selecting shape in header only Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You do realise this can be done with field coding, rather than via macros?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 10-09-2015, 12:51 AM
mhagi mhagi is offline selecting shape in header only Windows 7 64bit selecting shape in header only Office 2010 64bit
Novice
selecting shape in header only
 
Join Date: Oct 2015
Posts: 8
mhagi is on a distinguished road
Default selecting shapes in header only

Hi,

its depressing, but I do not.
Do not even know what you mean with field coding. Do you mean something like field function "Autotext"?

Hmmm, never thought about it.
Hmmmm, could work.
Hmmmmm, seems to be very good idea.
Hmmmmmmmmmmmmmm, seems to be about perfect!!!!

Will try (actually tried already, but have to test a lil bit more).

Thanks very very much

PS: sorry for mistakes and such. English is not my language. And not my machines either - it does underline almost anything in red.
Reply With Quote
  #6  
Old 10-09-2015, 01:10 AM
macropod's Avatar
macropod macropod is offline selecting shape in header only Windows 7 64bit selecting shape in header only Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

To do this with field coding, you could use the combination of an ASK field and an IF field.

The ASK field might be coded as: {ASK ShowHide "Display Logo (Y/N)?"}

The IF field for each image you want to conditionally show or hide might be coded as:
{IF{REF ShowHide \* Caps}<> "N*" "put image or its anchor here"}

Simply put the image or its anchor between the double-quotes surrounding the 'put image or its anchor here' text (which you can delete). With this approach, you'll get a pop-up any time the document is printed. Answering anything other than something beginning with N or n will cause the image to display and, hence, print.

Note: The field brace pairs (i.e. '{ }') for the above examples are all created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac); you can't simply type them or copy & paste them from this message. Nor is it practicable to add them via any of the standard Word dialogues. The spaces represented in the field construction are all required.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting Texts mohsen.amiri Word 5 02-19-2015 11:50 PM
selecting shape in header only Selecting First Columns mohsen.amiri Word Tables 1 09-01-2014 01:08 AM
Can command Advanved Filter do without selecting header(i.e. just process cells)? Aquinax Excel 3 08-10-2013 05:16 PM
selecting shape in header only Excel vba adding field in word table/shape in a header Hdr Excel 1 02-04-2013 04:40 PM
selecting shape in header only locking shape within shape cpwljaw Drawing and Graphics 1 08-28-2012 12:13 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:23 AM.


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