Greetings! I am new to the forum, and would like a simple question answered. I would like to add notes in from an excel spreadhseet to my drawing template. Modifying the "Set New Note Example" from the Solidworks API help file, I have made the code below:
'------------------------
Private Sub SetNotes_Click()
Dim swApp As Object ' Define variable used to hold the SldWorks object
Dim Model, DwgDoc As Object ' Define variable used to hold the ModelDoc & PartDoc objects
Dim SelMgr As Object ' Define variable used to hold the SelectionManager Object
Dim selObj As Object ' Variable for the selected object
Const swSelNOTES = 15 ' Value consistent with definitions in swconst.bas
Set swApp = CreateObject("SldWorks.Application") ' Attach to or open SolidWorks session
Set Model = swApp.ActiveDoc ' Grab the current document
Set DwgDoc = Model ' PartDoc & ModelDoc are same in VB
DwgDoc.EditTemplate ' Edit the current drawing template
Set View = DwgDoc.GetFirstView ' This is the template
Worksheets("Drawing Settings").Range("C9").Select
Dim DwgNotes As Range
Set DwgNotes = Range(Selection, Selection.End(xlDown)).Copy
Model.SelectByID "DwgNotes@Sheet Format1", "NOTE", 0, 0, 0 ' Select the note for the Drawing Name
Set SelMgr = Model.SelectionManager() ' Get the selection manager class
If (SelMgr.GetSelectedObjectCount <> 0) Then ' If user has selected something
Set selObj = SelMgr.GetSelectedObject2(1) ' Get the first item in the selection list
If (SelMgr.GetSelectedObjectType(1) = swSelNOTES) Then ' If selected object is a note
ret = selObj.SetText("NOTES:" & Chr(13) & Chr(10) & _
"<PARA indent=10 findent=-10 number=on ntype=1 nformat=$$. nstartNum=0>" & _
DwgNotes) ' Change the text in the note
If (ret = True) Then ' If change is successful
DwgDoc.EditRebuild ' Rebuild to see the change
Else ' If name change failed
swApp.SendMsgToUser ("Error changing note text.")
End If
Else ' If selected object was not a note
swApp.SendMsgToUser ("Please Select a Note for this operation.")
End If ' End if selected object was note or not
End If ' End if there is an object selected
End Sub
'-----------------
When I try to run the code, Excel highlights the nonblank cells and assigns them to the DwgNotes dim (at least I think it does) but I get an error that says "424, Object required". What is wrong with this code? I would think it would work, but I am not sure what I am missing, as I am a newbie in VBA (SWX or XL) and have been teaching myself in the process. Any insights??
THANKS!!!
'------------------------
Private Sub SetNotes_Click()
Dim swApp As Object ' Define variable used to hold the SldWorks object
Dim Model, DwgDoc As Object ' Define variable used to hold the ModelDoc & PartDoc objects
Dim SelMgr As Object ' Define variable used to hold the SelectionManager Object
Dim selObj As Object ' Variable for the selected object
Const swSelNOTES = 15 ' Value consistent with definitions in swconst.bas
Set swApp = CreateObject("SldWorks.Application") ' Attach to or open SolidWorks session
Set Model = swApp.ActiveDoc ' Grab the current document
Set DwgDoc = Model ' PartDoc & ModelDoc are same in VB
DwgDoc.EditTemplate ' Edit the current drawing template
Set View = DwgDoc.GetFirstView ' This is the template
Worksheets("Drawing Settings").Range("C9").Select
Dim DwgNotes As Range
Set DwgNotes = Range(Selection, Selection.End(xlDown)).Copy
Model.SelectByID "DwgNotes@Sheet Format1", "NOTE", 0, 0, 0 ' Select the note for the Drawing Name
Set SelMgr = Model.SelectionManager() ' Get the selection manager class
If (SelMgr.GetSelectedObjectCount <> 0) Then ' If user has selected something
Set selObj = SelMgr.GetSelectedObject2(1) ' Get the first item in the selection list
If (SelMgr.GetSelectedObjectType(1) = swSelNOTES) Then ' If selected object is a note
ret = selObj.SetText("NOTES:" & Chr(13) & Chr(10) & _
"<PARA indent=10 findent=-10 number=on ntype=1 nformat=$$. nstartNum=0>" & _
DwgNotes) ' Change the text in the note
If (ret = True) Then ' If change is successful
DwgDoc.EditRebuild ' Rebuild to see the change
Else ' If name change failed
swApp.SendMsgToUser ("Error changing note text.")
End If
Else ' If selected object was not a note
swApp.SendMsgToUser ("Please Select a Note for this operation.")
End If ' End if selected object was note or not
End If ' End if there is an object selected
End Sub
'-----------------
When I try to run the code, Excel highlights the nonblank cells and assigns them to the DwgNotes dim (at least I think it does) but I get an error that says "424, Object required". What is wrong with this code? I would think it would work, but I am not sure what I am missing, as I am a newbie in VBA (SWX or XL) and have been teaching myself in the process. Any insights??
THANKS!!!