VBA Code to Resize Logo in Word Header

The following code is an extract ....

For Each oSec In ActiveDocument.Sections

     oSec.Headers(wdHeaderFooterPrimary).Range.ParagraphFormat.Alignment = wdAlignParagraphRight

     oSec.Headers(wdHeaderFooterPrimary).Range.InlineShapes.AddPicture FileName:=strLogo, LinkToFile:=False, SaveWithDocument:=True

Next oSec

The code works OK, but the logo is too big for the header area.

Are there any parameters that will allow me to resize it whilst retaining the ratio.

Thanks in anticipation

  

Answer
Answer

Use the following instead:

Dim oSec As Section
Dim oHeader As HeaderFooter
Dim oLogo As InlineShape
    For Each oSec In ActiveDocument.Sections
        Set oHeader = oSec.Headers(wdHeaderFooterPrimary)
        With oHeader.Range
            .ParagraphFormat.Alignment = wdAlignParagraphRight
            Set oLogo = .InlineShapes.AddPicture(Filename:=strLogo, LinkToFile:=False, SaveWithDocument:=True)
        End With
        With oLogo
            .Height = 75
            .Width = 100
        End With
    Next oSec

Graham Mayor (Microsoft Word MVP 2002-2019)
For more Word tips and downloads visit my web site
https://www.gmayor.com/Word_pages.htm

1 person found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated May 7, 2023 Views 1,721 Applies to: