VBA - Gem som pdf
HejJeg har tidligere fået assistance til nedenstående, så jeg kan gemme excel-filen som pdf via en VBA-knap.
Når jeg vil gemme, så foreslås der ikke et filnavn, da feltet til filnavnet er tom.
Kan det gøres sådan, at den automatisk foreslår filnavnet fra excel i dette felt, når jeg vil gemme som pdf?
Sub Gemsompdf()
Dim wks As Worksheet
For Each wks In Worksheets
If wks.Range("H9").Value2 = "Ikke gyldig" Or wks.Range("H9").Value2 = "Gyldig" Then
wks.Visible = xlSheetVisible
End If
Next
' * ' Initialize
On Error Resume Next
' * ' Define variables
Dim FirstSheet As String
Dim WS As Excel.Worksheet
Dim PDFFile As String
PDFFile = Application.GetSaveAsFilename(FileFilter:="PDF (*.PDF), *.PDF")
If Len(PDFFile) < xlLess Then GoTo ES: ' User clicked [Cancel]
' * ' Find first sheet to export
For Each WS In ActiveWorkbook.Worksheets
If UCase$(WS.Range("H9").Value) = "GYLDIG" And WS.Visible = xlSheetVisible Then
FirstSheet = WS.Name
WS.Select
Exit For
End If
Next
If FirstSheet = "" Then GoTo ES: ' No valid worksheet found
' * ' Select the rest of the worksheets to be exported
For Each WS In ActiveWorkbook.Worksheets
If UCase$(WS.Range("H9").Value) = "GYLDIG" And WS.Visible = xlSheetVisible Then WS.Select False
Next
' * ' Create PDF
Err.Clear
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDFFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
If Err.Number <> 0 Then Debug.Print Err.Number & ", " & Err.Description
ES: ' End of Sub
Set WS = Nothing
Worksheets(4).Select
End Sub
VH CHC