![]() Print_path = os.path.abspath('./Selection_Printer.xlsm') :param col_max: ending column of the selection desired as an integer :param col_min: starting column of the selection desired as an integer :param row_max: ending row of the selection desired as an integer :param row_min: starting row of the selection desired (Excel uses indexing :param xl_path: Full path to XL file that has cell selection to be printed Program that calls the selection printing Macro in Excel from Python In my Python code I call this macro using the following code: import osĭef excel_jpg_macro(xl_path, row_min, row_max, col_min, col_max): This prints a cell range defined by minRow, maxRow, minCol, and maxCol in the worksheet at the Path location of wbPath. Cells(minRow, maxCol).Select 'start by selecting upper left corner Sub SelectRange(sh As Worksheet, minRow As Integer, maxRow As Integer, minCol As Integer, maxCol As Integer) Selection.PrintOut From:=1, To:=1, Copies:=1, Collate:=True ' but another parameter could be added to make this dynamicĬall SelectRange(sh, minRow, maxRow, minCol, maxCol) 'All of the sheets I wanted to print were "Sheet1", Then in one of the VBA modules in that Excel file I wrote the following code: Sub PrintSelection(wbPath As String, minRow As Integer, maxRow As Integer, minCol As Integer, maxCol As Integer) xlsm extension (I called mine Selection_Printer.xlsm. The first thing I needed was to create a dummy/blank Excel file with an. ![]() The solution launches a custom Excel Macro from a Python routine. ![]() OK, I found a way to do this myself, so I thought I'd post how I did it.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |