Below Vba to save as pdf and also not overwite

Millfurn

New Member
Joined
Oct 21, 2021
Messages
4
Office Version
  1. 2013
In need of assistance, i would like to use the below code (if possible) but have it save as pdf and not overwrite it. It will be assigned to a button. Thanks in advance

Private Sub CommandButton1_Click()

With Application.FileDialog(msoFileDialogSaveAs)
.Title = "PLease choose a location and file name to save"
.ButtonName = "Save Tracker"
.InitialFileName = "E:\Tony\Tracker\" & Range("L1").Value
If .Show = 0 Then
MsgBox "The file did not save.", vbCritical
Exit Sub
End If
Application.DisplayAlerts = False
.Execute
Application.DisplayAlerts = True
End With

End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
In need of assistance, i would like to use the below code (if possible) but have it save as pdf and not overwrite it. It will be assigned to a button. Thanks in advance

Private Sub CommandButton1_Click()

With Application.FileDialog(msoFileDialogSaveAs)
.Title = "PLease choose a location and file name to save"
.ButtonName = "Save Tracker"
.InitialFileName = "E:\Tony\Tracker\" & Range("L1").Value
If .Show = 0 Then
MsgBox "The file did not save.", vbCritical
Exit Sub
End If
Application.DisplayAlerts = False
.Execute
Application.DisplayAlerts = True
End With

End Sub
I got it was easy in the end used th '.FilterIndex PDFIndex command after .InitialFileName
Thanks
 
Upvote 0
HI All, i ended up changing my approach found this code (below) that does exactly what i want. I will share if anyone else needs similar.
thank you all for even reading my post!

Sub Test()


Dim i As Integer, PDFindex As Integer
Dim PDFfileName As String

With ActiveWorkbook
PDFfileName = .Worksheets(6).Range("L1").Value & .Worksheets(6).Range("L1").Value & ".pdf"
End With

With Application.FileDialog(msoFileDialogSaveAs)

PDFindex = 0
For i = 1 To .Filters.Count
If InStr(VBA.UCase(.Filters(i).Description), "PDF") > 0 Then PDFindex = i
Next

.Title = "Save workbook as PDF"
.ButtonName = "Saver Tracker"
.InitialFileName = "Ticks"
.FilterIndex = PDFindex

If .Show Then
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, filename:=.SelectedItems(1), _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End If

End With

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,575
Messages
6,125,619
Members
449,240
Latest member
lynnfromHGT

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