View Single Post
 
Old 01-19-2018, 03:16 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

If there is a table in each footer of each section then the following will put a selected image into the first row second cell of that table and the image will shrink to the width of the cell.

Code:
Sub Logo()
Dim fDialog As FileDialog
Dim strLogo As String
Dim oTable As Table
Dim oCell As Range
Dim oSection As Section
Dim oFooter As HeaderFooter

    Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
    With fDialog
        .AllowMultiSelect = False
        .Filters.Clear
        .Filters.Add "Graphics Files", "*.jpg,*.png,*.tif, *.bmp, *.gif"
        .InitialFileName = Environ("USERPROFILE") & "\Pictures\"
        .InitialView = msoFileDialogViewList
        If Not .Show = -1 Then
            MsgBox "User cancelled"
            GoTo lbl_Exit
        End If
    End With
    strLogo = fDialog.SelectedItems(1)

    For Each oSection In ActiveDocument.Sections
        For Each oFooter In oSection.Footers
            If oFooter.Exists Then
                If oFooter.Range.Tables.Count > 0 Then
                    Set oTable = oFooter.Range.Tables(1)
                    If oTable.Rows(1).Cells.Count > 1 Then
                        oTable.AutoFitBehavior wdAutoFitFixed
                        Set oCell = oTable.Cell(1, 2).Range
                        oCell.End = oCell.End - 1
                        oCell.Text = ""
                        oCell.InlineShapes.AddPicture strLogo
                    End If
                End If
            End If
        Next oFooter
    Next oSection
lbl_Exit:
    Set oSection = Nothing
    Set oFooter = Nothing
    Set oTable = Nothing
    Set oCell = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote