Issue Printing to PDF using a Command Button and VBA

PandaPlaza1277

New Member
Joined
Aug 2, 2022
Messages
8
Office Version
  1. 2013
Platform
  1. Windows
Hello,

I'm running into an issue printing a specific hidden spreadsheet to PDF using a Command Button. I've managed to make this code work in another workbook of mine and I've even had this code work a number of times in this spreadsheet (maybe 4 times or so earlier on). For some reason, it does not consistently work. I've spent a good amount of time searching for answers and verifying the code that seems to be in question, but as far as I can tell, the input is correct. The error seems to be occurring with the "OpenAfterPublish:=True" line of code. Does anyone have any ideas what could be going wrong?
 

Attachments

  • Print Summary to PDF.jpg
    Print Summary to PDF.jpg
    98.6 KB · Views: 12
Update - I was able to get the "? pdffile" code to work. It now displays "...\Desktop\301600 - Summary Analysis - 8/4/2022.pdf", just like it should. After the adjustments, I had to close out the workbook and reopen it to be able to rerun the "? pdffile" code in the Immediate Window.
However, the same issue persists with the printing function.
 

Attachments

  • Update - Print Summary to PDF.jpg
    Update - Print Summary to PDF.jpg
    90.5 KB · Views: 3
Upvote 0

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
You'll need to replace those forward slashes ( / ) with some other character, maybe a dash ( - ) instead. So, for example, assuming that the format for your date is "m/d/yyyy", replace...

VBA Code:
SumAn.Range("C10").Value

with

VBA Code:
Format(SumAn.Range("C10").Value, "m-d-yyyy")

Change the format accordingly.

Hope this helps!
 
Upvote 0
My apologies, earlier in this thread when I listed the illegal characters for a filename, I forgot to include the forward slash and the backslash. I have edited that post to include these characters.
 
Upvote 0
My apologies, earlier in this thread when I listed the illegal characters for a filename, I forgot to include the forward slash and the backslash. I have edited that post to include these characters.
AHA!!! That was it! The code was referencing a cell (C10), which was formatted as a date, and using either the special character "/" or "-".
I switched the cell C10 to the General format and adjusted the formula in the cell to use the TEXT("m.d.yy") function and it's working now!
Thank you so much!!!
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,917
Members
449,093
Latest member
dbomb1414

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