Save a PDF error

josullivan601632

New Member
Joined
Aug 23, 2020
Messages
39
Office Version
  1. 2007
Platform
  1. Windows
Hi someone very kindly helped me with a VBA code to save to a pdf which worked wonders and I was so grateful. I have continued working on the workbook and moved a few things around, and now the code will not work.

the code is

Sub SaveAsPDF1()
Dim strTempFile As String
Dim strData As String
Dim spath As String

spath = Environ("USERPROFILE") & "\Newman Refrigeration Ltd\Newman Refrigeration Ltd - General\Brian\Cost Book\"
strData = Sheets("Quotation").Range("K9").Value & " - " & Sheets("Quotation").Range("K1").Value & ".pdf"
strTempFile = spath & strData
MsgBox strData, , "PDF has been saved with the following filename:"

Sheets("Quotation").ExportAsFixedFormat Type:=xlTypePDF, Filename:=strTempFile, OpenAfterPublish:=True

As I have changed the layout of the worksheet I now need the file name to be "L6" and "L2"instead of what is in red above, so I changed these references in the code and now get the Error 400. I have painstakingly tried everything, even starting a fresh with a new workbook, but I get so far and then go back to getting the error 400. I have even tried having K9 = L6 and K1 = L2 on the sheet to get around this, but this also returns the error.

I have been trying to fix this for over a week now and am so frustrated, can anyone suggest what I might be doing wrong? or how I get around this. If was such a nice feature for my workbook as I use the PDF's created to create a flipbook for the sales team!

Any wise words are much appreciated

Jo
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Have you tried stepping through the code (F8) to see which line is causing the problem?
 
Upvote 0
Also, have you confirmed that L6 and L2 do not contain any invalid characters for a filename, such as { } \ : ", etc?
 
Upvote 0
Hi I thought I had tried everything, the cells were a formula (a TEXT & formula) and that contained a "/".

It all works lovely, I can't believe I struggled for so long trying to work it out.

have a great evening :)
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,603
Members
449,038
Latest member
Arbind kumar

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