{"text_format":"1","workbook":"xlsx","n_sheets":2,"sheets":["附件打印工具","Code"],"not_rendered":{"charts":0,"images":0,"macros":1,"external_links":0,"defined_names":0,"comments":0,"pivot_tables":0},"unopened":[],"bounds":{"document_bytes":16777216,"sheet_cells":100000,"rows_first":2000,"rows_last":500,"rows_between":2000,"halvings":0,"cell_chars":16384,"cell_head_chars":4096},"cells_cut":0,"cells_raw":0,"read":"whole","date_system":"1900"}

{"sheet":"附件打印工具","index":0,"n_rows":10,"n_cols":4,"rows_kept":10,"cut":false,"hidden":false,"merged":[]}
["Made by Ryan",null,null,"2025-01-24"]
[]
["How to use the tool:"]
[]
["1.将需要打印的函证附件Excel放到本地某个文件夹里"]
["2.启用宏"]
["3.Fn+ESC(FnLock)"]
["4.Alt+F8, 启用宏文件"]
["5.选择文件夹，并选择打印列（A到K就是收入附件）"]
["6.等待完成"]

{"sheet":"Code","index":1,"n_rows":85,"n_cols":1,"rows_kept":85,"cut":false,"hidden":false,"merged":[]}
["Sub PrintSheetsToPDF()"]
["    Dim folderPath As String"]
["    Dim fileName As String"]
["    Dim wb As Workbook"]
["    Dim pdfFolderPath As String"]
["    Dim folderDialog As FileDialog"]
["    Dim startColumn As String, endColumn As String"]
["    Dim printRange As String"]
["    Dim ws As Worksheet"]
["    Dim pdfFileName As String"]
["    Dim sheetIndex As Integer"]
[]
["    ' Prompt user to select the folder"]
["    Set folderDialog = Application.FileDialog(msoFileDialogFolderPicker)"]
["    With folderDialog"]
["        .Title = \"Select Folder Containing Excel Files\""]
["        If .Show <> -1 Then Exit Sub ' Exit if the user cancels"]
["        folderPath = .SelectedItems(1) & \"\\\""]
["    End With"]
[]
["    ' Prompt user to enter the column range"]
["    startColumn = InputBox(\"Enter the starting column (e.g., A):\", \"Define Print Range\")"]
["    If startColumn = \"\" Then Exit Sub ' Exit if the user cancels"]
["    endColumn = InputBox(\"Enter the ending column (e.g., Z):\", \"Define Print Range\")"]
["    If endColumn = \"\" Then Exit Sub ' Exit if the user cancels"]
["    printRange = startColumn & \":\" & endColumn"]
[]
["    ' Create a subfolder for PDFs if it doesn't exist"]
["    pdfFolderPath = folderPath & \"PDFs\\\""]
["    If Dir(pdfFolderPath, vbDirectory) = \"\" Then MkDir pdfFolderPath"]
[]
["    ' Process each Excel file in the folder"]
["    fileName = Dir(folderPath & \"*.xls*\") ' Get the first Excel file"]
["    Do While fileName <> \"\""]
["        ' Open the workbook"]
["        Set wb = Workbooks.Open(folderPath & fileName)"]
[]
["        ' Loop through only the first two sheets (if they exist)"]
["        For sheetIndex = 1 To 2"]
["            If sheetIndex <= wb.Sheets.Count Then"]
["                Set ws = wb.Sheets(sheetIndex)"]
[]
["                ' Define the print area and set narrow margins"]
["                With ws.PageSetup"]
["                    .PrintArea = printRange"]
["                    .TopMargin = Application.InchesToPoints(0.25)"]
["                    .BottomMargin = Application.InchesToPoints(0.25)"]
["                    .LeftMargin = Application.InchesToPoints(0.25)"]
["                    .RightMargin = Application.InchesToPoints(0.25)"]
["                    .HeaderMargin = Application.InchesToPoints(0.1)"]
["                    .FooterMargin = Application.InchesToPoints(0.1)"]
[]
["                    ' Focus only on the width: fit the columns to 1 page wide"]
["                    .Zoom = False ' Disable automatic zoom scaling"]
["                    .FitToPagesWide = 1 ' Fit to 1 page wide"]
["                    .FitToPagesTall = False ' Do not scale the height, let Excel handle it"]
[]
["                    ' Optional: Set the page orientation to landscape if necessary"]
["                    ' If ws.UsedRange.Columns.Count > 10 Then"]
["                    '     .Orientation = xlLandscape"]
["                    ' End If"]
["                End With"]
[]
["                ' Auto-resize columns to prevent \"####\" from appearing"]
["                ws.Columns.AutoFit"]
[]
["                ' Generate PDF file name"]
["                pdfFileName = pdfFolderPath & Left(fileName, InStrRev(fileName, \".\") - 1) & \"-\" & Format(sheetIndex, \"00\") & \".pdf\""]
[]
["                ' Export the sheet to PDF"]
["                ws.ExportAsFixedFormat Type:=xlTypePDF, fileName:=pdfFileName, Quality:=xlQualityStandard, _"]
["                                       IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False"]
["            End If"]
["        Next sheetIndex"]
[]
["        ' Close the workbook to release memory"]
["        wb.Close SaveChanges:=False"]
["        Set wb = Nothing"]
[]
["        ' Process the next file"]
["        fileName = Dir"]
["    Loop"]
[]
["    MsgBox \"Finished & Happy New Year! - Ryan\", vbInformation"]
["End Sub"]