VBA - Export to PDF will not take images with it.

wes2422

New Member
Joined
Feb 8, 2019
Messages
4
The issue I am having is that when I export the file to a PDF using VBA I loose my company logo at the top of the pdf version of the worksheet. It for some reason will not export with the file. While when I "print to pdf" it will stay attached. I have tried doing a command so that it prints to PDF and automatically save it in the same location with the same name with the current date but it will not let me "select a printer" as part of the command, so when I close out of the file and reopen it, it defaults back to the default printer without selecting "print to pdf". I have tried linking the image to cells, print area, and various areas of the work sheet with no luck. Does anyone have any incite into this? Below is the VBA formula I currently have.

Sub ExportPDF()
Dim sFile As String
sFile = ThisWorkbook.Path & "" & ActiveWorkbook.Name & Format(Date, "mm-dd-yy")

Sheets("Sheet1").Select
ActiveSheet.PageSetup.PrintArea = "$B$1:$Z$68"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=sFile, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=True
End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
I tested your code with minor modifications of the file name and it saved the pictures to the resulting PDF file. The pictures are pasted to B3 to B5 in Sheet1. I then tested the same code on Sheet3 where the pictures, also in B3 to B5, are linked to those in Sheet1. They were also saved to PDF. Maybe it's the logo in your file that is causing the problem. Is the logo in header? I did not test that.

Code:
Sub ExportPDF()
Dim sFile As String
sFile = ThisWorkbook.Path & "\" & ActiveWorkbook.Name & Format(Date, "mm-dd-yy") & ".PDF"

Sheets(1).Select
ActiveSheet.PageSetup.PrintArea = "$B$1:$Z$68"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=sFile, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=True
End Sub
 
Upvote 0
If you select the picture and right click to get "Format Picture",is the "Print Object" choice unchecked?
 
Upvote 0
Thank you both for the replies. I actually figured it out. It was only doing it because my default printer for some reason would delete it. As soon as I changed my default printer to the other one in the office the picture prints every time. Thanks again for the input!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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