Forum Discussion
HowardPitchon
Sep 23, 2024Copper Contributor
VBA to set logo in the header as Decorative
I have macro code to set Alt Text for small images in a document to Decorative.
Sub alttext()
Dim shp As InlineShape
Dim doc As Document
Set doc = ActiveDocument
For Each shp In doc.InlineShapes
If shp.Width >= InchesToPoints(2) And shp.Height >= InchesToPoints(1) Then
shp.AlternativeText = "Figure. Caption."
Else
shp.Decorative = True
End If
Next shp
End Sub
Works great. However, it overlooks the image in the Header for some reason.
I need to set Alt Text for my logo in the Header to Decorative.
I cannot seem to figure this one out.
Please help.
2 Replies
Sort By
To also access the shapes in the Header(s) of the document, you would need to use something like:
Sub alttext() Dim shp As InlineShape Dim doc As Document Dim h As Long Dim s As Long Set doc = ActiveDocument For Each shp In doc.InlineShapes If shp.Width >= InchesToPoints(2) And shp.Height >= InchesToPoints(1) Then shp.AlternativeText = "Figure. Caption." Else shp.Decorative = True End If Next shp For s = 1 To doc.Sections.Count With doc.Sections(s) For h = 1 To .Headers.Count For Each shp In .Headers(h).InlineShapes If shp.Width >= InchesToPoints(2) And shp.Height >= InchesToPoints(1) Then shp.AlternativeText = "Figure. Caption." Else shp.Decorative = True End If Next shp Next h End With Next s End Sub
- HowardPitchonCopper Contributor
This seems very logical and elogant. Thank you.
I am getting a compile error and I don't see why.
Attached is a simple document I am using to test. The original script works fine. When attempting to get into the Header, things go awry.
Thank you for your time with all this. I really appreciate it.