Help with VBA

inspectorNDT

New Member
Joined
May 10, 2019
Messages
16
I am really new to VBA's. I am trying to make a "create PDF" button to make a PDF out of the active tab. The file name would be using cells on the active tab then the name of the tab and then another cell.

I would also like it to prompt the user if a file of the same name exist and I would like it to auto save to the active users desktop.

thank you in advance for your help
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
The cell O2 has the date, sadly in a format that contains illegal characters !!
Way back in post #13 I asked this question about illegals !!
Use this code to rectify the runtime error and note the line in RED

Code:
Private Sub CommandButton1_Click()
Dim nm As String, stFileName As String
Dim saveInFolder As String, celOne As String, celTwo As String, celThree As String
saveInFolder = Environ("USERPROFILE") & "\Desktop\"
nm = ActiveSheet.Name
celOne = Range("D1").Value
celTwo = Range("C5").Value
[b][color=red]celThree = Format(Range("O2"), "ddmmmyy")[/color][/b]
stFileName = saveInFolder & celOne & celTwo & nm & celThree
If Dir(stFileName) <> "" Then
MsgBox "Specified File Exists", vbInformation, "File Error"
Exit Sub
Else
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=stFileName & ".pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,945
Messages
6,181,937
Members
453,074
Latest member
JefersonKollet

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