How to get the excel file which can be modified from SW by macros?

Hi All,

I am working on SW macros, i have to create a excel file with name which can be modify SW part file and other way around  too.I have to call parts from the SW environment to excel file by macros. I am having basic understanding of VBA programming.

I have created a macro but it gives me error when i am adding "Excel.ActiveWorkbook" function in macros. I have also tried "Workbook.SaveAs" function but it did not work out for me.

I am forwarding the partial code which i have created.

Any kind of help is very much appreciated.

Thanks,

Raj Dave.

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim i As Integer

Dim PartCount As Integer

Dim longwarnings As Long, longstatus As Long

Dim instance As IModelDoc2

'Excel file open

Sub main()

'Set xl = GetObject(, "Excel.Application")

Dim xlApp As Excel.Application

Dim xlBook As Excel.Workbook

Dim xlSheet As Excel.Worksheet

'Set xlSheet = xl.ActiveSheet

Dim strFileName As String

'Solidworks variable definition

'Function GetPathName(Tool_Spec_System1) As String

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Set xlApp = CreateObject("Excel.Application")

Dim Part As Object

Set Part = swApp.OpenDoc6("C:\Solidworks\Tool_Spec_System1.SLDPRT", 1, 0, "", longstatus, longwarnings)

swApp.ActivateDoc2 "Tool_Spec_System1.SLDPRT", False, longstatus

Set Part = swApp.ActiveDoc

Dim f1 As String

Dim Folderpath As String

'Dim f1 As SldWorks.ModelDoc2

f1 = swModel.GetPathName()

For i = 1 To 20

        If f1 = Tool_Spec_System1 Then

        PartCount = i

        End If

Next i

out:

' Define the folderpath

Folderpath = swModel.GetPathName()

strFileName = Folderpath & "\Master.xls"

'Open (Master.xlsx, Update Links:=0) For Random As Workbook

Dim MkDir As String

MkDir = Folderpath

xlApp.Visible = True

Set xlBook = Excel.ActiveWorkbook("Folderpath \ Master.xls", FileFormat:=56)

Set xlSheet = CreateObject("Excel.Sheet")

xlSheet.Application.Workbooks.Open "Master.xls"

End Sub( )

SolidworksApi macros