VBA code for "Save As" dialog box and PDF File format

DAD

Board Regular
Joined
Jan 8, 2010
Messages
54
Hi Ladies and Gents,

I am very new at VBA coding in excel, so please excuse my lack of technical literacy.

I am trying to write a simple VBA script in my excel spreadsheet and link it to a button so when pressed, the "Save As" dialog box opens and the "Format" defaults to PDF. That is the main objective of the script. I am also interested to know if it is possible to insert words (from two cells in the spreadsheet) into the "File Name" section of the "Save As" dialog box?

The reason I don't want to run an export as PDF script as I have need in other threads in the forum, is that many colleagues will be running this spreadsheet, and they need the ability to save the files wherever they desire on their machine.

I hope my query is clear and contains enough info.

Thanks in advance for any help.
 
Hi Mike,

Thanks again, it is now almost perfect. The only problem I have now is that the workbook has 6 worksheets. When I execute the code, it saves all 6 workouts as separate files. Is there a way to just save the active worksheet, not all 6?

The code I have thus far is:

Sub Save_as_PDF()

Dim strAA7 As String, strL7 As String, strFileName As String

strL7 = Range("L7").Value
strAA7 = Range("AA7").Value
strFileName = strL7 & "-" & strAA7


Application.Dialogs(xlDialogSaveAs).Show "" & strFileName, 46


End Sub



Thanks again for your help, it is very much appreciated.
 
Last edited:
Upvote 0

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Towards the bottom of the dialog, there is an option button to select Save Workbook or Worksheet.
I don't know how to set that button to default to Worksheet
 
Upvote 0

Forum statistics

Threads
1,223,315
Messages
6,171,416
Members
452,401
Latest member
Stereonix

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