Ilogic get Excel sheet names

Ilogic get Excel sheet names

bronc3buster842001
Advocate Advocate
371 Views
2 Replies
Message 1 of 3

Ilogic get Excel sheet names

bronc3buster842001
Advocate
Advocate

I have an Excel wookbook that has multiple sheets. How to I get the sheet names to use to make a multivalue parameter.

0 Likes
Accepted solutions (1)
372 Views
2 Replies
Replies (2)
Message 2 of 3

A.Acheson
Mentor
Mentor
Accepted solution

Try this out. Ensure the header references are not removed. The second sub routine just creates the parameter. 

Option Explicit On
AddReference "Microsoft.Office.Interop.Excel.dll"
Imports Excel = Microsoft.Office.Interop.Excel

Sub Main

	Dim xlFilePath As String  = "C:\Users\XlFile.xlsx"
	Dim wsList As New List(Of String)
	
	CreateTxtParam("XlSheetNames", "")
	
	Dim excelApp As Excel.Application = CreateObject("Excel.Application")
	excelApp.Visible = True
	excelApp.DisplayAlerts = True
	
	Dim wb As Excel.Workbook = excelApp.Workbooks.Open(xlFilePath)
	
	For Each ws As Excel.Worksheet In wb.Worksheets
		wsList.Add(ws.Name)	
	Next
	 
	 MultiValue.List("XlSheetNames") = wsList
	 
	Dim Name As String = InputListBox("Prompt", MultiValue.List("XlSheetNames"), Name, Title := "Title", ListName := "List")

End Sub

Sub CreateTxtParam(Name As String, value As String)
	Dim doc As Document = ThisDoc.Document
	Dim Param As Parameter
	
	If doc.DocumentType = DocumentTypeEnum.kPartDocumentObject _
		Or doc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
		
		Dim def As ComponentDefinition = doc.ComponentDefinition
		
		Try
			Param = def.Parameters(Name)
		Catch
			Param = def.Parameters.UserParameters.AddByValue(Name,value, UnitsTypeEnum.kTextUnits)
		End Try
	
	ElseIf doc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
		
		Try
			Param = doc.Parameters(Name)
		Catch
			Param = doc.Parameters.UserParameters.AddByValue(Name,value, UnitsTypeEnum.kTextUnits)
		End Try
		
	End If
	
End Sub
	  

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 3

bronc3buster842001
Advocate
Advocate

Thanks. That works. Ill play around with it so I understand how it works