Results 1 to 9 of 9
  1. #1
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    ASKER, Norway
    Posts
    277
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Inserted Pictures change number?? (Win 2000, Office XP)

    For a short time ago I got a good help with hiding/showing an inserted logo in the Header.

    I had to find out which Picture number each picture (a .gif file inserted) had and then it worked perfectly. But ..... after some days it did not work any more. Checking the procedure I found that the picture no. had changed. I thought that the picture no. would remain the same even when I made the a new document from the template.

    I have two logos(pictures) placed above each other and uses the code to hide one of them or hiding both at a time. In the procedure shown I have used "picture no" to hide/show the particular picture, but as said it has changed number. How come? And what is really happening?
    Here's my code (which HansV helped me with):

    Sub BlackAndWhiteLogo() ' shows black logo
    Dim sec As Section
    Dim hdr As HeaderFooter
    Dim i As Integer

    Dim rng As Range

    For Each sec In ActiveDocument.Sections
    For Each hdr In sec.Headers
    Set rng = hdr.Range
    For i = 1 To rng.ShapeRange.Count ' Fields.Count
    With rng.ShapeRange(i) ' Fields(i)
    ' MsgBox rng.ShapeRange(i).Name ' Fields(i)
    If .Name = "Picture 26" Then
    .Visible = msoFalse
    End If
    If .Name = "Picture 25" Then
    .Visible = msoFalse
    End If
    If .Name = "Picture 22" Then
    .Visible = msoCTrue
    End If
    If .Name = "Picture 23" Then
    .Visible = msoCTrue
    End If
    End With
    Next i
    Next hdr
    Next sec

    ActiveDocument.CustomDocumentProperties("LOGOSVISI BLE") = True
    ActiveDocument.CustomDocumentProperties("BWLogoVis ible") = True
    ActiveDocument.CustomDocumentProperties("ColLogoVi sible") = False


    Set sec = Nothing
    Set hdr = Nothing
    Set rng = Nothing
    End Sub

    If I have to check each time which number the black and the colored logo has, how can I do that? I cannot see how I can distinguish between the black and the colored ones without observing it by stepping through the code.

    Can any one give me a solution or explanation??

    Thanks!

    Bjorn

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Inserted Pictures change number?? (Win 2000, Office XP)

    This is mysterious to me; where are the other 20+ pictures? Does Word just increment the number even if you delete them? What a mess.

    Try this: see if you can assign your own names to shapes (in a PowerPoint thread, it was said you could do this with a little VBA, if it can't be done interactively). If you can do that in your template, I would expect better results.

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Inserted Pictures change number?? (Win 2000, Office XP)

    Names such as Picture 37 are maintained by Word itself. If you want stable names, assign them yourself, for example:

    ActiveDocument.Sections(1).Headers(wdHeaderFooterP rimary).Range.ShapeRange(2).Name = "Bjorn37"

    Word won't change the name Bjorn37.

  4. #4
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    ASKER, Norway
    Posts
    277
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Re: Inserted Pictures change number?? (Win 2000, Office XP)

    Thanks Hans!

    You always have the good solutions. I will try tomorrow morning, its become 01:30 and time to get some sleep.


    Thanks again!!!

    Bjorn

  5. #5
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    ASKER, Norway
    Posts
    277
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Re: Inserted Pictures change number?? (Win 2000, Office XP)

    Thanks Hans,

    I tried this and managed to name only the pictures in the first section. At this moment I do not have more than one section, but I have a page setup as "Different first page" and then the code wouldn't name the two pictures situated in the next Header.

    Haven't been able to find out how to be able to count / name the other two pictures.

    Are there any code to catch the pictures in the next Header in this case?

    Regards

    Bjorn

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Inserted Pictures change number?? (Win 2000, Office XP)

    The following code will sequentially number all pictures in all headers as Bjorn1, Bjorn2 etc. Use a name that can't cause conflicts with names you have already assigned.

    Sub SetPicNames()
    Dim sec As Section
    Dim hdr As HeaderFooter
    Dim shp As Shape
    Dim i As Long

    For Each sec In ActiveDocument.Sections
    For Each hdr In sec.Headers
    For Each shp In hdr.Range.ShapeRange
    i = i + 1
    shp.Name = "Bjorn" & i
    Next shp
    Next hdr
    Next sec

    Set shp = Nothing
    Set hdr = Nothing
    Set sec = Nothing
    End Sub

    You can test the names before and after by running the following macro (results will be in the Immediate window):

    Sub ListShapeNames()
    Dim sec As Section
    Dim hdr As HeaderFooter
    Dim shp As Shape

    For Each sec In ActiveDocument.Sections
    For Each hdr In sec.Headers
    For Each shp In hdr.Range.ShapeRange
    Debug.Print shp.Name
    Next shp
    Next hdr
    Next sec

    Set shp = Nothing
    Set hdr = Nothing
    Set sec = Nothing
    End Sub

  7. #7
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    ASKER, Norway
    Posts
    277
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Re: Inserted Pictures change number?? (Win 2000, Office XP)

    Thanks Hans,

    I'll implement it asap.

    What should I have done without help from WOODY's ??

    Thanks a lot!!!

    Bjorn

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Inserted Pictures change number?? (Win 2000, Office XP)

    If you want to keep track of the section and header in the names of the pictures, you could use the following macro. It will assign names like Pic_3_2_1 signifying 3rd sector, 2nd header, 1st picture. But of course, if you rearrange the document, the numbering won't be updated automatically, so you would have to run the macro again with a different name.

    Sub SetShapeNames()
    Dim sec As Section
    Dim hdr As HeaderFooter
    Dim shp As Shape
    Dim iSec As Long
    Dim iHdr As Long
    Dim iShp As Long
    iSec = 0
    For Each sec In ActiveDocument.Sections
    iSec = iSec + 1
    iHdr = 0
    For Each hdr In sec.Headers
    iHdr = iHdr + 1
    iShp = 0
    For Each shp In hdr.Range.ShapeRange
    iShp = iShp + 1
    shp.Name = "Pic_" & iSec & "_" & iHdr & "_" & iShp
    Next shp
    Next hdr
    Next sec
    Set shp = Nothing
    Set hdr = Nothing
    Set sec = Nothing
    End Sub

  9. #9
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    ASKER, Norway
    Posts
    277
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Re: Inserted Pictures change number?? (Win 2000, Office XP)

    Thanks again,
    This will be very useful. It gives a good overview of the pictures.

    I'll implement it when I have gone through and tested it out.

    Thanks Hans!!!!

    Regards

    Bjorn

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •