• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Help in VB Code, Save PDF File on same file location and then in a folder

Ateeb Ali

Member
Hi, I am using following code but it is giving me error,
two purpose
1. Make one "folder" (if not already available) on same location of original excel file.
2. Save pdf file on this folder with name as cell range "T3"

MY code
Code:
Sub PDFActiveSheet()
Dim PDFFileName As String

 If Dir(ThisWorkbook.Path & "\GGT PDF", vbDirectory) = vbNullString Then MkDir ThisWorkbook.Path & "\GGT PDF"
    PDFFileName = GeneratedFileName(ThisWorkbook.Path & "\GGT PDF\ " & Range("T3").Value, 0)


ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:=PDFFileName, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True



End Sub




Function GeneratedFileName(FileName As String, i As Integer)
Dim testFileName As String
testFileName = FileName
If i <> 0 Then
testFileName = FileName & " (" & i & ")"
End If
GeneratedFileName = testFileName
If Dir(testFileName & ".pdf", vbNormal) > "" Then
GeneratedFileName = GeneratedFileName(FileName, i + 1)
End If

End Function
 
Back
Top