I am working on a add-in for SolidWorks PDM, it should do the following:
Save BOM to CSV
Convert CSV to Excel
The first part is working, but the second part, where it should convert, is missing something and I can't figure out what.
The line where I open the csv-file wb=Workbooks.Open() has the following error: Reference to a non-shared member requires an object reference. This is why I have the filesystemobject in my code, but htat did not help.
Can anyone tell my what to do?
Thanks Sussi
Imports Microsoft.Office.Interop.Excel
Imports EdmLib
Imports Scripting
Module Module1
Dim vault As IEdmVault20 = New EdmVault5
Dim file As IEdmFile16
Dim fold As IEdmFolder11
Dim _fold As IEdmFolder11
Dim bomFile As IEdmFile16
Dim CurRev As String
Dim bomMgr As IEdmBomMgr
Dim bomView As IEdmBomView3
Dim i As Integer = 0
Dim str As String = ""
Dim arrSize As Integer
Dim csvName As String
Dim excelName As String
Dim Filepath As String
Sub Main()
vault.LoginAuto("ODIN", 0)
fold = vault.RootFolder
file = vault.GetFileFromPath("C:\ODIN\project\16xxx\16368 ODIN Engineering Slagelse Test af Solidworks og PDM\01 Drawings Parts and Assemblies\01 SW Files\16368.01.sldasm")
_fold = vault.GetFolderFromPath("C:\ODIN\project\16xxx\16368 ODIN Engineering Slagelse Test af Solidworks og PDM\01 Drawings Parts and Assemblies\01 SW Files")
CurRev = file.CurrentRevision
Dim fileNameNoExt = IO.Path.GetFileNameWithoutExtension(file.Name)
csvName = "Temp_" + fileNameNoExt + "-Rev-" + CurRev + ".csv"
'Get BOM Name "ODIN BOM", configuration "Default"
bomMgr = vault.CreateUtility(EdmUtility.EdmUtil_BomMgr)
Dim ppoRetLayouts() As EdmBomLayout = Nothing
Dim ppoRetLayout As EdmBomLayout
bomMgr.GetBomLayouts(ppoRetLayouts)
ppoRetLayout.mbsLayoutName = "ODIN BOM NAV info"
bomView = file.GetComputedBOM(ppoRetLayout.mbsLayoutName, -1, "Default", 1)
'Display BOM view row and column information
Dim ppoRows() As Object = Nothing
Dim ppoRow As IEdmBomCell
bomView.GetRows(ppoRows)
i = 0
arrSize = ppoRows.Length
str = ""
While i < arrSize
ppoRow = ppoRows(i)
'bomFile = vault.GetFileFromPath(ppoRow.GetPathName)
str = "BOM Row " & i & ": " & vbLf & "Item ID:" & ppoRow.GetItemID & vbLf & "Path name: " & ppoRow.GetPathName & vbLf & "Tree level: " & ppoRow.GetTreeLevel & vbLf & " Is locked? " & ppoRow.IsLocked
'MsgBox(str)
i += 1
End While
'bomView.SaveToCSV("C:\Users\sbi\Desktop\BOMtest\" + csvName, False)
'Convert CSV to Xlsx
excelName = fileNameNoExt + "-Rev-" + CurRev + ".xlsx"
Filepath = "C:\Users\sbi\Desktop\BOMtest\"
'Open csv-file
Dim x As Object
' x = Shell("""explorer.exe"" ""C:\Users\sbi\Desktop\BOMtest\""" & csvName & """")
Dim FSO As Object
Dim csvFolder As Object
FSO = CreateObject("Scripting.FileSystemObject")
csvFolder = FSO.GetFolder(Filepath)
Dim wb As Workbook
wb = Workbooks.Open(csvFolder + csvName,, ";",,,,,,,,,,,,)
wb.SaveAs("C:\Users\sbi\Desktop\BOMtest\" + excelName)
wb.Close()
End Sub
End Module```