' This code has been generated by AI. Original prompt:
' I need a script which creates a table for data present in a range in excel sheet. I need the range of sheet where data is present , it should not be passed always
Dim objExcel, objWorkbook, objWorksheet, objRange, objListObject
' Create an instance of Excel
Set objExcel = CreateObject("Excel.Application")
' Open the workbook
Set objWorkbook = objExcel.Workbooks.Open("%ExcelFilePath%")
' Set the worksheet (1 means the first sheet)
Set objWorksheet = objWorkbook.Worksheets("%ExcelSheet%")
' Find the last used row and column
lastRow = objWorksheet.Cells(objWorksheet.Rows.Count, 1).End(-4162).Row ' -4162 is equivalent to xlUp
lastCol = objWorksheet.Cells(1, objWorksheet.Columns.Count).End(-4159).Column ' -4159 is equivalent to xlToLeft
' Define the range where data is present
Set objRange = objWorksheet.Range(objWorksheet.Cells(1, 1), objWorksheet.Cells(lastRow, lastCol))
' Add a ListObject (table) to the range
Set objListObject = objWorksheet.ListObjects.Add(1, objRange, , 1) ' 1 is equivalent to xlSrcRange and xlYes
' Save and close the workbook
objWorkbook.Save
objWorkbook.Close
' Quit Excel
objExcel.Quit
' Clean up
Set objListObject = Nothing
Set objRange = Nothing
Set objWorksheet = Nothing
Set objWorkbook = Nothing
Set objExcel = Nothing
stampcoin
57
Michael E. Gernaey
47
Super User 2025 Season 1
rzaneti
29
Super User 2025 Season 1