Hallo
Ik was op zoek naar een macro om het equivalent van de actie [Alt + TAB] uit te voeren (actief document wijzigen) en ik vond deze code:
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim vModels As Variant
Dim count As Integer
Dim opendocs As New Collection
Dim docname As Variant
Dim currentdocTitle As String
Dim title As String
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
currentdocTitle = swModel.GetTitle
vModels = swApp.GetDocuments
For count = LBound(vModels) To UBound(vModels) 'get list of open documents
Set swModel = vModels(count)
If swModel.Visible <> False Then
opendocs.Add (swModel.GetTitle)
End If
Next
count = 0
If opendocs(opendocs.count) = currentdocTitle Then ' if its the last document in the list, switch to the first document
swApp.ActivateDoc2 opendocs(1), False, 0
End
Else ' else find the next document and activate
For count = 1 To opendocs.count
If opendocs(count) = currentdocTitle Then
swApp.ActivateDoc2 opendocs(count + 1), False, 0
End
End If
Next
End If
End Sub
en het werkt perfect wanneer de start van deze macro rechtstreeks via SolidWorks.
Mijn probleem is dat ik een tool maak die via Excel start en daarom al mijn macro's in VBA Excel moet schrijven en niet in VBA Solidworks.
wanneer ik deze code kopieer / plak in mijn Excel-macro, is hier de foutmelding die ik krijg:
run-time error '438'
Object doesn't support this property or method
Als ik op debuggen klik, wordt deze regel voor mij gemarkeerd
Set swApp = Application.SldWorks
Ik heb verschillende dingen geprobeerd, maar ik heb niet veel idee meer...
Op de vorige macro's heb ik deze code:
Set swApp = CreateObject("SldWorks.application")
Dus ik heb geprobeerd hetzelfde te doen voor deze, maar het werkt niet, ik krijg deze foutmelding:
Run-time error'13':
Tpe mismatch
wijzend naar deze regel:
swApp.ActivateDoc2 opendocs(1), False, 0
op VBA Excel heb ik de referenties SldWorks 2017 Type Library, SOLIDWORKS 2017 Commends type library en SOLIDWORKS 2017 Constant type library ingeschakeld.
Heeft iemand enig idee?
Bij voorbaat dank
Yves