+ Reply to Thread
Results 1 to 8 of 8

export sheet as pdf , problem with fitting column and range

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-28-2013
    Location
    Ljubljana
    MS-Off Ver
    Office 365
    Posts
    1,054

    export sheet as pdf , problem with fitting column and range

    Good morning all
    can advice me for the following code i get from internet that will export sheet name summary to pdf file with name of value from B2
    the problem now is
    i try to change in code to fit range that i need in exported PDF file and print only range A1:C105 or end of row have value instead of C105
    but not working
    the code is
    Sub PDFActiveSheetNoPromptCheck()
    
    
    Dim wsA As Worksheet
    Dim wbA As Workbook
    Dim strName As String
    Dim strPath As String
    Dim strFile As String
    Dim strPathFile As String
    Dim myFile As Variant
    Dim lOver As Long
    Dim rng As Range
    
    
    On Error GoTo errHandler
    
    Set wbA = ActiveWorkbook
    Set wsA = ActiveSheet
    
    'get active workbook folder, if saved
    strPath = wbA.Path
    If strPath = "" Then
      strPath = Application.DefaultFilePath
    End If
    strPath = strPath & "\"
    
    strName = wsA.Range("B2").Value _
              & " Interpretation "
    
    Set rng = Sheets("Summery").Range("A1:C105")   
    
    
    
    'create default name for savng file
    strFile = strName & ".pdf"
    strPathFile = strPath & strFile
    
    If bFileExists(strPathFile) Then
      lOver = MsgBox("Overwrite existing file?", _
        vbQuestion + vbYesNo, "File Exists")
      If lOver <> vbYes Then
        'user can enter name and
        ' select folder for file
        myFile = Application.GetSaveAsFilename _
          (InitialFileName:=strPathFile, _
              FileFilter:="PDF Files (*.pdf), *.pdf", _
              Title:="Select Folder and FileName to save")
        If myFile <> "False" Then
          strPathFile = myFile
        Else
          GoTo exitHandler
        End If
      End If
    End If
    
    'export to PDF in current folder
    wsA.ExportAsFixedFormat _
        Type:=xlTypePDF, _
        FileName:=strPathFile, _
        Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, _
        OpenAfterPublish:=False
    
    'confirmation message with file info
    MsgBox "PDF file has been created: " _
      & vbCrLf _
      & strPathFile
    
    exitHandler:
        Exit Sub
    errHandler:
        MsgBox "Could not create PDF file"
        Resume exitHandler
    End Sub
    
    Function bFileExists(rsFullPath As String) As Boolean
      bFileExists = CBool(Len(Dir$(rsFullPath)) > 0)
    End Function

  2. #2
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: export sheet as pdf , problem with fitting column and range

    Sub J3v16()
    Dim File As String
    With Sheets("Summary")
        File = ThisWorkbook.Path & "\" & .Range("B2").Value & " Interpretation "
        .Range("A1:C" & .Cells(.Rows.Count, 3).End(xlUp).Row).ExportAsFixedFormat xlTypePDF, File, xlQualityStandard
    End With
    End Sub
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  3. #3
    Forum Contributor
    Join Date
    11-28-2013
    Location
    Ljubljana
    MS-Off Ver
    Office 365
    Posts
    1,054

    Re: export sheet as pdf , problem with fitting column and range

    Dear sintek
    thank you so much for your very simple and smart code
    i have some note
    1- its not give message for file present or not , its overwrite without any message
    2- PDF file created have whole range even empty row , can neglect empty row from range

  4. #4
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: export sheet as pdf , problem with fitting column and range

    1- its not give message for file present or not , its overwrite without any message
    If pdf already exists, what must happen?

    2- PDF file created have whole range even empty row , can neglect empty row from range
    Supply sample file and specify exactly what range must be exported...
    See Top Yellow banner regarding sample file...

  5. #5
    Forum Contributor
    Join Date
    11-28-2013
    Location
    Ljubljana
    MS-Off Ver
    Office 365
    Posts
    1,054

    Re: export sheet as pdf , problem with fitting column and range

    1- if already exist , show box say file present if you need to overwrite or to save as with different name
    2-as in attached photo you can see result of file that have empty row printed
    the whole range is A1:C105 but not all the time this range have data sometimes like in attached example have only data till C56 and the rest is empty
    Attached Images Attached Images
    Last edited by mazan2010; 05-29-2021 at 05:03 AM.

  6. #6
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: export sheet as pdf , problem with fitting column and range

    Images mean nothing!!!
    As I said previous post...
    Supply sample file and specify exactly what range must be exported...
    See Top Yellow banner regarding sample file...

  7. #7
    Forum Contributor
    Join Date
    11-28-2013
    Location
    Ljubljana
    MS-Off Ver
    Office 365
    Posts
    1,054

    Re: export sheet as pdf , problem with fitting column and range

    finally i find the error as i find some cell is merged in my file
    than you so much for your help and solution

  8. #8
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: export sheet as pdf , problem with fitting column and range

    Thanks for rep + ...

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Multiple Sheet Export to PDF, one sheet needs specific range based lastrow of data
    By xlyfe in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-25-2018, 07:39 PM
  2. [SOLVED] macro to export range of column to PDF
    By mazan2010 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-30-2016, 02:32 PM
  3. problem fitting data to chart
    By Rob1956 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 12-13-2013, 08:44 PM
  4. VBA: issue fitting picture to range
    By nmgmarques in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-29-2012, 02:30 PM
  5. Problem with trend line fitting
    By enp1ld in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 05-04-2009, 04:03 PM
  6. Curve fitting/goal seek problem
    By rambochuck in forum Excel General
    Replies: 6
    Last Post: 04-03-2008, 10:40 AM
  7. Best fitting a range of data to a particular value
    By eaton.rob@gmail.com in forum Excel General
    Replies: 0
    Last Post: 04-07-2006, 10:25 PM

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