I have an Excel file "Random Part Numbers" that I need to open, copy the the data from cell A1, overwrite this value the "PARTNUM" custom property of the new, open, and unsaved part, then close the Excel file. So far, the open an close commands work, but copying the Excel data and overwriting the parts custom property is holding me up.

Any help would be appreciated. Im new to macros & VB.

This is what I have so far:

Option Explicit

Dim xlRange As Range

Dim swCustPrpMgr As SldWorks.CustomPropertyManager

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim xlApp As Excel.Application

Dim xlSheet As Excel.Worksheet

Dim xlBooks As Excel.Workbooks

' Open Excel workbook

Sub Main()

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Set xlApp = CreateObject("Excel.Application")

xlApp.Visible = True

xlApp.Workbooks.Open "H:\CAD\SolidWorks\Macros\Random Part Numbers.xlsx"

Set xlSheet = xlApp.ActiveSheet

' Copy data from Excel to Custom Properties

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Set xlApp = GetObject(, "Excel.Application")

Set xlSheet = xlApp.ActiveSheet

Name = xlSheet.Cells(1, 1)

swModel.AddCustomInfo3 "", "PARTNUM", swCustomInfoText, Name

' Close Excel

xlApp.Workbooks.Close

xlApp.Quit

End Sub

Jhon, As you had asked in your very 1st question that "

I have an Excel file "Random Part Numbers" that I need to open, copy the the data from cell A1, overwrite this value the "PARTNUM" custom property of the new, open, and unsaved part, then close the Excel file. So far, the open an close commands work, but copying the Excel data and overwriting the parts custom property is holding me up"following code Copying the Excel data and overwriting the parts custom property

'Option Explicit

Dim xlRange As Object

Dim swCustPrpMgr As SldWorks.CustomPropertyManager

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim xlApp As Object

Dim xlSheet As Object

Dim xlBooks As Object

' Open Excel workbook

Sub Main()

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Set xlApp = CreateObject("Excel.Application")

xlApp.Visible = True

xlApp.Workbooks.Open "C:\Users\abhishek.l\Desktop\New Microsoft Excel Worksheet.xlsx"

Set xlSheet = xlApp.ActiveSheet

' Copy data from Excel to Custom Properties

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

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

' Set xlSheet = xlApp.Sheets(1)

Name = xlSheet.Cells(1, 1)

swModel.DeleteCustomInfo2 "", "PARTNUM"

swModel.AddCustomInfo3 "", "PARTNUM", swCustomInfoText, Name

' Close Excel

xlApp.Workbooks.Close

xlApp.Quit

End Sub