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 Eac...
Jan 06, 2025
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
- HowardPitchonJan 13, 2025Copper 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.