Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have an Excel wookbook that has multiple sheets. How to I get the sheet names to use to make a multivalue parameter.
Solved! Go to Solution.
I have an Excel wookbook that has multiple sheets. How to I get the sheet names to use to make a multivalue parameter.
Solved! Go to 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