Wednesday, August 8, 2018

Convert a complete or partial worksheet of excel to pdf using VBA ,VBA Teacher Sourav,Kolkata 8910141720

Private Sub CommandButton1_Click()

Dim code As String
Dim mtd As String
Dim pdffolder As FileDialog

code = Range("m3").Text
mtd = Range("u7").Text

Set pdffolder = Application.FileDialog(msoFileDialogFolderPicker)
pdffolder.AllowMultiSelect = False
pdffolder.Show

    If Range("m3") = "" Then
   
        MsgBox ("Please Enter a Stockist Code")
       
    Else
   
        Dim dir As String
        dir = pdffolder.SelectedItems(1)
   
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=dir & "\" & code & "_" & mtd & ".pdf", openafterpublish:=False
               
        MsgBox ("PDF Generated")
               
        End If
       
End Sub

No comments:

Post a Comment