Hello friends, Any one know how to get all sheet names of excel using modern activities. Is there any way to get without excel scope.
Thanks in advance
Hello friends, Any one know how to get all sheet names of excel using modern activities. Is there any way to get without excel scope.
Thanks in advance
Without scope ypu cannot get them
this is how you can create list of sheetnames
Cheers
Hi @aslam_ali1
Use Get Workbook Sheets which is an Classic activity.
If with Modern activities follow below steps
Use Excel File=> For Each Excel Sheet => Use Message box and give CurrentSheet.Name
.
Or
Use this code
Sub GetSheetNamesAndSave()
Dim ws As Worksheet
Dim outputText As String
For Each ws In ThisWorkbook.Sheets
outputText = outputText & ws.Name & vbCrLf
Next ws
Open "C:\Path\To\Output.txt" For Output As #1
Print #1, outputText
Close #1
End Sub
Write this in a text document and save that file.
Drag and drop Invoke VBA and pass the filepath.
Hope it helps!!
Hi @aslam_ali1 ,
Could you maybe check with the below workflow :
Excel_GetWorkbookSheets.zip (9.3 KB)
It uses DocumentFormat.OpenXml
methods in Invoke Code
activity to get the sheet names.
Let us know if this doesn’t work.
Well u can get it with GET WORKBOOK SHEETS activity
Download example here
Or u can try this also
Or
If that’s the case then u can try with coding options
Like
Using vb net on invoke code activity
Dim excelApp As Microsoft.Office.Interop.Excel.Application
Dim excelBook As Microsoft.Office.Interop.Excel.Workbook
' Provide the path to your Excel file
Dim filePath As String = "YourFilePath.xlsx"
' Initialize Excel Application
excelApp = New Microsoft.Office.Interop.Excel.ApplicationClass()
' Open the Excel workbook
excelBook = excelApp.Workbooks.Open(filePath)
' Create a list to store sheet names
Dim sheetNames As New List(Of String)
' Loop through each worksheet and add its name to the list
For Each sheet As Microsoft.Office.Interop.Excel.Worksheet In excelBook.Sheets
sheetNames.Add(sheet.Name)
Next
' Close the workbook and Excel application
excelBook.Close(False)
excelApp.Quit()
' Release COM objects to prevent memory leaks
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelBook)
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp)
' Now, the sheet names are stored in the sheetNames list
' You can use them as needed
Using python with “Run Python Script” activity
import pandas as pd
# Provide the path to your Excel file
file_path = "YourFilePath.xlsx"
# Read the Excel file into a Pandas DataFrame
xls = pd.ExcelFile(file_path)
# Get the sheet names
sheet_names = xls.sheet_names
# Output the sheet names
print(sheet_names)
Hope this helps
Cheers @aslam_ali1
Thank you all for your kind support
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.