sorry for the inconvenience. I've tried to google (I always said "google is my friend"), but everything I try only give me an error in VBA.
I would like to add a function, which replace invalid characters (!"#¤%&/()=?`^*>;:@£${[]}|~\,.'¨´+-) in filename with "_".
This is my current (and working) macro:
Sub Save_to_PDF()
Dim v As Variant
Dim name, datedd As String
ThisWorkbook.Sheets(Array("sheet1")).Select
datedd = Date
strFilename = Worksheets("sheet1").Range("B2")
v = Application.GetSaveAsFilename(strFilename & " document " & datedd & " .pdf", "PDF Files (*.pdf), *.pdf")
On Error GoTo openfile
If FileExists(v) Then
Kill v
End If
If VarType(v) = vbString Then
ThisWorkbook.Sheets("sheet1").Activate
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, filename:=v, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, From:=1, To:=1, OpenAfterPublish:=True
End If
Exit Sub
openfile:
MsgBox "You have one file open allready whith that name. Please try again", vbInformation, "Please close file"
Exit Sub
End sub
End Sub
doesn't feature at any point, perhaps that will lead to some issues - could you change the lastExit
to anEnd
? – Greedo Aug 2 '17 at 11:06