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

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

yky

Well-known Member
Joined
Jun 7, 2011
Messages
1,867
Office Version
  1. 2010
Platform
  1. Windows
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
 

jolivanes

Well-known Member
Joined
Sep 5, 2004
Messages
1,712
Office Version
  1. 2013
  2. 2007
Platform
  1. Windows
If you select the picture and right click to get "Format Picture",is the "Print Object" choice unchecked?
 

wes2422

New Member
Joined
Feb 8, 2019
Messages
4
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!
 

Watch MrExcel Video

Forum statistics

Threads
1,129,804
Messages
5,638,450
Members
417,025
Latest member
MusterDuster

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
Top