Insert picture JPG in footer

sm789

New Member
Joined
Aug 17, 2014
Messages
30
Office Version
  1. 2011
Platform
  1. MacOS
Hello everybody!

I need to add a picture (jpg) file as a footer and then save the file as a pdf.

I got this done:

VBA Code:
Sub Macro1()
With ActiveSheet.PageSetup.RightFooterPicture
       .FileName = "/Users/mac/Desktop/Picture1.jpg"
   End With
   ActiveSheet.PageSetup.RightFooter = "&G"

    Sheets("1111").Select
    Range("Print_Area").Select
    
    'You can specify the range rather than Print Area. In which case you need to rem the line above
    ' and remove REM from below two lines
'            Set rr = ActiveWorkbook.Sheets("1111").Range("a1:f55")
'            rr.Select
    
' Retrieve settings
                WhereTo1 = Range("Z67").Value
                WhereTo2 = Range("AA67").Value
                Stamp = Range("C68").Value
    
' Check if Stamp-field has any value, if not, add the current date.
                If Stamp = "" Then Stamp = Date

' Assemble the filename
                sFileName1 = WhereTo1 & Stamp & y & ".pdf"
     
' Check if the File Already Exists
             If Dir(sFileName1) = "" Then
             GoTo SaveFile1:
            Else
            End If
    
    Select Case MsgBox("This file exists. Continue & overwrite?", vbYesNo Or _
        vbExclamation Or vbDefaultButton1, "")
        Case vbYes
        GoTo SaveFile1:
        
        Case vbNo
        GoTo SecondFile:
        End Select
 
' Save the File as PDF

SaveFile1:
                ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=sFileName1, Quality _
                :=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
                OpenAfterPublish:=False
        
' Assemble the second filename

SecondFile:
                sFileName2 = WhereTo2 & Stamp & y & ".pdf"

' Check if the File Already Exists
                If Dir(sFileName2) = "" Then
                GoTo SaveFile2:
                Else
                End If
    
    Select Case MsgBox("This file exists. Continue & overwrite?", vbYesNo Or _
        vbExclamation Or vbDefaultButton1, "")
        Case vbYes
        GoTo SaveFile2:
        
        Case vbNo
        GoTo Continue:
        End Select


        '' Save the Second File as PDF
         
SaveFile2:
                ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=sFileName2, Quality _
                :=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
                OpenAfterPublish:=False
        
'' End of PDF creation

Continue:

End Sub

My question is that at the beginning of this code, I have specified a filename. I would like the code to ask me to choose the file. Is it at all possible? I am a Mac user so don't know if that is at all an issue.

Thanks a ton//
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
If I was doing this in Windows, it would look something like this.

VBA Code:
    Dim strFile As String
    strFile = InputBox("Enter file including full path")
    MsgBox fileWithPath
    
    ActiveSheet.PageSetup.RightFooterPicture.Filename = fileWithPath
    'etc. etc. etc.
 
Upvote 0
I think the GetOpenFilename method works with Mac VBA too, so if you adjusted @martinshort's helpful code above slightly, you could do something like

VBA Code:
Dim strFile As String
StrFile = Application.GetOpenFilename
ActiveSheet.PageSetup.RightFooterPicture.Filename = strFile
 
Upvote 0
I think the GetOpenFilename method works with Mac VBA too, so if you adjusted @martinshort's helpful code above slightly, you could do something like

VBA Code:
Dim strFile As String
StrFile = Application.GetOpenFilename
ActiveSheet.PageSetup.RightFooterPicture.Filename = strFile
Thank you for your help! The first part works very well. I checked with MsgBox the value of strFile was accurate with complete path. However, it did not add that image file as Right Footer. Am I missing anything?
 
Upvote 0
If I was doing this in Windows, it would look something like this.

VBA Code:
    Dim strFile As String
    strFile = InputBox("Enter file including full path")
    MsgBox fileWithPath
   
    ActiveSheet.PageSetup.RightFooterPicture.Filename = fileWithPath
    'etc. etc. etc.
Thank you. I wanted the code to open a finder window and allow me to choose the file rather than enter the path and filename. Dan W's suggestions of Application.GetOpenFilename works but it is not adding the image file as right footer. The code returns no error though..
 
Upvote 0
Just an additional line to Dan's code.
Code:
Dim strFile As String
strFile = Application.GetOpenFilename
    With ActiveSheet.PageSetup
        .RightFooterPicture.Filename = strFile
        .RightFooter = "&G"    '<---- Add this line
    End With
 
Upvote 0
Solution
Just an additional line to Dan's code.
Code:
Dim strFile As String
strFile = Application.GetOpenFilename
    With ActiveSheet.PageSetup
        .RightFooterPicture.Filename = strFile
        .RightFooter = "&G"    '<---- Add this line
    End With
Thank you Jolivanes and thank you Dan. The additional line did the trick.

Much appreciated.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top