Hello,
I have a macro that Saves to Pdf an invoice and gives the user the possiblity to choose the folder.
ISSUE 1: The macro works for ordinary folder, but if user selects "Desktop" it gives error 91: "Object Variable or With block variable not set".
ISSUE 2: Also when user hits "Cancel" in the Brower for folder section, it gives error 1004: "Document not Saved. the docoment may be open or an error may have been encountered when saving". How can i do to not have this message and to just cancel ?
This is the code:
Thanks !
I have a macro that Saves to Pdf an invoice and gives the user the possiblity to choose the folder.
ISSUE 1: The macro works for ordinary folder, but if user selects "Desktop" it gives error 91: "Object Variable or With block variable not set".
ISSUE 2: Also when user hits "Cancel" in the Brower for folder section, it gives error 1004: "Document not Saved. the docoment may be open or an error may have been encountered when saving". How can i do to not have this message and to just cancel ?
This is the code:
Code:
Sub savetopdf()
s = Range("S3").Value
v = Range("D10").Value
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
GetFolder & "\" & "F" & s & "-" & v & ".pdf", Quality:=xlQualityStandard, IncludeDocProperties _
:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
End Sub
Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Alegeti un folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
Thanks !