PDF Save Button auto filename according to 2 cells

jefflab1

New Member
Joined
Jul 9, 2015
Messages
14
I have researched other threads on this forum, but I keep having issues.

Requirements:
Save PDF button
File name is from 2 different cell values - cell C2 and C3 example: \10-01-2020-0000
Location: is a shared drive on a network server at work. (not sure if this maters)
C2 is a date - format is mm-dd-yyyy
C3 is a time - format is text - ####

Thank you in advance for your help, I've been going on 16 hours working on this and getting frustrated.

Jeff
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Try this:

VBA Code:
Sub SavePDF()
'https://www.mrexcel.com/board/threads/pdf-save-button-auto-filename-according-to-2-cells.1147263/
Dim SvNm As String
On Error GoTo EH

'SvNm = InputBox(Prompt:="Enter file name to use when saving", Title:="Enter Save Name", Default:="Enter Filename here...")
SvNm = Range("C2").Value & "-" & Range("C3").Value

'Check and replace fwd slashes (/) with underscores (_)
SvNm = Replace(SvNm, "/", "_")

Application.PrintCommunication = True

'   ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
'       "C:\Desktop\TestFolder\" & SvNm & ".pdf", Quality:=xlQualityStandard, _
'       IncludeDocProperties:=False, IgnorePrintAreas:=False, OpenAfterPublish:=True
       
       
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        "https://workplace.sharepoint.com/teams/1234/" & SvNm & ".pdf", Quality:=xlQualityStandard, _
        IncludeDocProperties:=False, IgnorePrintAreas:=False, OpenAfterPublish:=True
       
Range("A1").Select
Exit Sub
EH:
MsgBox ("File not saved, File Name possibly invalid, Check you have no special characters in cells C2 and C3")
Range("A1").Select

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,525
Messages
6,120,051
Members
448,940
Latest member
mdusw

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