据我记忆和所知,ModelDoc2对象上从来没有GetCurrentSheet方法,它实际上是DrawingDoc类型的方法。
因此,阅读您的代码,我认为ActiveDoc不是DrawingDoc。可以肯定的是,只需使用:
Dim swApp as SldWorks
Dim swDrawing as DrawingDoc
Dim swDocument as ModelDoc2
Set swApp = Application.SldWorks
Set swDocument = swApp.ActiveDoc
Set swDrawing = swDocument
If swDrawing is Nothing Then
MsgBox "No valid drawing doc!"
Exit Sub
End If
或者
Dim swApp as SldWorks
Dim swDrawing as DrawingDoc
Dim swDocument as ModelDoc2
Set swApp = Application.SldWorks
Set swDocument = swApp.ActiveDoc
If swDocument.GetType() <> swDocumentTypes_e.swDocDRAWING Then
MsgBox "No valid drawing doc!"
Exit Sub
Else
Set swDrawing = swDocument
End If
你知道是否是这种情况。我还建议您查看 API 文档中的以下附加信息:
http://help.solidworks.com/2013/English/api/sldworksapi/solidworks.interop.sldworks~solidworks.interop.sldworks.idrawingdoc~getcurrentsheet.html
http://help.solidworks.com/2013/English/api/sldworksapi/Get_and_Set_Sheet_Properties_Example_VB.htm