+ Reply to Thread
Results 1 to 5 of 5

Code to save sheet as "PDF" to Desktop - Based on ComboBox 1 Value

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-22-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    329

    Code to save sheet as "PDF" to Desktop - Based on ComboBox 1 Value

    Hi all,

    Does anyone have a code that can be attached to a cmd button on a userform that will copy the worksheet as displayed in "combobox1" to the desktop as a PDF file? Trying to record the macro but failing miserably, this is my code so far & any assistance will be greatly appreciated, thank you all & have a great day


    Private Sub CommandButton5_Click()
      
    Set ws = Worksheets(Me.ComboBox1.Value)
    
     If Blank Then
        MsgBox "Please Enter Branch"
        Exit Sub
      End If
        
        Worksheets(Me.ComboBox1.Value).Select
        ChDir "C:\Users\username\Desktop"
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
            "C:\Users\username\Desktop\Rcd1.pdf", Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
            True
            
        
            Application.ScreenUpdating = True
            
    End Sub

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Code to save sheet as "PDF" to Desktop - Based on ComboBox 1 Value

    Private Sub CommandButton5_Click()
      
    Set ws = Worksheets(Me.ComboBox1.Value)
    If Blank Then
        MsgBox "Please Enter Branch"
        Exit Sub
    End If
    strFilePath "C:\Users\username\Desktop\"
    strPdfName = "Rcd1.pdf"
    Worksheets(Me.ComboBox1.Value).Copy
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFilePath & strPdfName, _
      Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
      OpenAfterPublish:=False
    ActiveWorkbook.Close (False)
       
    End Sub
    If solved remember to mark Thread as solved

  3. #3
    Forum Contributor
    Join Date
    04-22-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    329

    Re: Code to save sheet as "PDF" to Desktop - Based on ComboBox 1 Value

    Hi patel,

    Sorry for the delayed response, I've been away. Tried your code but for some reason it fails @ strFilePath "C:\Users\username\Desktop\" ??? Thanks for your time patel! - Marco

  4. #4
    Forum Contributor
    Join Date
    04-22-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    329

    Re: Code to save sheet as "PDF" to Desktop - Based on ComboBox 1 Value

    Hi Patel,

    A few tweaks & now works perfect! grazie mille!

     Private Sub CommandButton5_Click()
      
    Set ws = Worksheets(Me.ComboBox1.Value)
    
     If Blank Then
        MsgBox "Please Enter Branch"
        Exit Sub
      End If
         Worksheets(Me.ComboBox1.Value).Visible = True
        Worksheets(Me.ComboBox1.Value).Select
        ChDir "C:\Users\username\Desktop"
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
            "C:\Users\username\Desktop\CM1.pdf", Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
            True
    ActiveSheet.Visible = False
       
    End Sub

  5. #5
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Code to save sheet as "PDF" to Desktop - Based on ComboBox 1 Value

    prego mille

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1