+ Reply to Thread
Results 1 to 1 of 1

Merging Two VBA Codes - Insert XL Stored Image & Unique Last Page Footer

  1. #1
    Registered User
    Join Date
    03-28-2019
    Location
    California
    MS-Off Ver
    2016
    Posts
    2

    Merging Two VBA Codes - Insert XL Stored Image & Unique Last Page Footer

    I have found the following two VBA codes that individually address parts of my problem, but I need help merging the two. The first code takes an XL stored image (separate sheet) and inserts it in the footer. I need this because if I simply reference a file on the computer, when I copy the XL to another computer, the new computer doesn't have the file.

    Sub AddPicsToFooter()
    Dim strPicPath As String
    Dim strImageName As String
    Dim strImageSheetName As String

    ' change this to match your image control name
    strImageName = "Image1"
    ' change this to match the name of the sheet with the image on
    strImageSheetName = "SheetName"

    strPicPath = ThisWorkbook.Path & Application.PathSeparator & "temp.bmp"
    ' delete pic file if it already exists
    If Dir(strPicPath) <> vbNullString Then Kill strPicPath

    ' save picture to file
    SavePicture ThisWorkbook.Worksheets(strImageSheetName).OLEObjects(strImageName).Object.Picture, strPicPath

    ' now assign to active sheet footer
    With ActiveSheet.PageSetup
    .CenterFooterPicture.Filename = strPicPath
    .CenterFooter = "&G"
    End With

    ' remove temporary file
    Kill strPicPath
    End Sub

    The second code sets one image for a standard repeated footer and another image for a unique last page footer.

    Sub test()
    Dim TotPages As Long
    TotPages = Application.ExecuteExcel4Macro("GET.DOCUMENT(50)")
    With ActiveSheet.PageSetup
    .CenterFooter = "Image1 (Repeated Footer)"
    ActiveSheet.PrintOut From:=1, To:=TotPages - 1
    .CenterFooter = "Image2 (Last Page Footer)"
    ActiveSheet.PrintOut From:=TotPages, To:=TotPages
    End With
    End Sub
    Last edited by andydavidbrown; 03-28-2019 at 09:21 AM. Reason: Attempt at Code Tags

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Embed Image in xlam and insert in header / footer using macro / VBA
    By TheRune in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 03-28-2019, 06:00 AM
  2. insert image in header and footer vba is available thogh book is closed
    By jpbisani in forum Word Programming / VBA / Macros
    Replies: 1
    Last Post: 12-02-2018, 06:13 PM
  3. Text to insert page number in footer
    By dastgir in forum Excel General
    Replies: 3
    Last Post: 08-04-2018, 05:21 AM
  4. [SOLVED] VBA to insert page total (print area) in footer with cell-like formatting
    By leb123 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-01-2017, 04:33 PM
  5. [SOLVED] Insert Image into Mail from Folder in which Workbook is stored
    By Jonathan78 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-21-2016, 02:44 PM
  6. Insert right footer on current page into cell?
    By farzyness in forum Excel General
    Replies: 0
    Last Post: 08-25-2010, 04:46 PM
  7. [SOLVED] Auto Insert Page numbers without Footer
    By Keith in forum Excel General
    Replies: 2
    Last Post: 04-28-2006, 04:40 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1