Hier gebruiken we schroeven met specifieke nummers. Deze schroeven worden op basis van hun nummer op het netwerk opgeslagen. Ik probeer een macro te maken die het nummer in een excel ophaalt en vervolgens de genoemde schroef in de actieve assemblage plaatst. Tot nu toe lukt het me om de schroef open te krijgen, maar onmogelijk om in te brengen, kun je me helpen?
Bedankt
Sub ouvrirdanssolidworks()
'
'Option Explicit
Dim swApp As Object, swModel As Object
Dim myError As Long, myWarning As Long
Dim swAssembly As Object
Set swApp = CreateObject("SldWorks.Application")
If swApp.GetDocumentCount = 0 Then
MsgBox "Aucun fichier ouvert"
Set swApp = Nothing
End If
Set swModel = swApp.ActiveDoc
'If swModel.GetType <> swDocASSEMBLY Then
'MsgBox "Le document actif n'est pas un assemblage"
'End
'End If
a = ActiveCell.Value
b = "C:\EPDM_VAULT1\1 000 00x-Fournitures\"
c = 1
d = Val(Right(ActiveCell.Value, 3))
e = Left(ActiveCell.Value, 6)
If Val(Right(ActiveCell.Value, 3)) > 499 Then c = 2
AssemblyTitle = swModel.GetTitle
Set swAssembly = swModel
If c = 1 Then fichier = "C:\EPDM_VAULT1\1 000 00x-Fournitures\" & e & "000-" & e & "499\" & a & ".sldprt"
If c = 2 Then fichier = "C:\EPDM_VAULT1\1 000 00x-Fournitures\" & e & "500-" & e & "999\" & a & ".sldprt"
Set swModel = swApp.OpenDoc6(fichier, 1, 0, "", myError, myWarning)
If c = 1 Then fichier = "C:\EPDM_VAULT1\1 000 00x-Fournitures\" & e & "000-" & e & "499\" & a & ".prt"
If c = 2 Then fichier = "C:\EPDM_VAULT1\1 000 00x-Fournitures\" & e & "500-" & e & "999\" & a & ".prt"
Set swModel = swApp.OpenDoc6(fichier, 1, 0, "", myError, myWarning)
'insérer
swApp.ActivateDoc2 AssemblyTitle, False, longstatus
'Set Part = swApp.ActiveDoc
'Set swComponent = swAssembly.AddComponent(AssemblyTitle, "", 0, 0, 0)
End Sub
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim myError As Long
Dim myWarning As Long
Dim swAssembly As SldWorks.ModelDoc2
Dim fichier As String
Dim swcomponent As SldWorks.Component2
Sub ouvrirdanssolidworks()
Set swApp = CreateObject("SldWorks.Application")
If swApp.GetDocumentCount = 0 Then
MsgBox "Aucun fichier ouvert"
Set swApp = Nothing
End If
Set swModel = swApp.ActiveDoc
AssemblyTitle = swModel.GetTitle
fichier = "C:\xxx\xxx.sldprt"
Set swModel = swApp.OpenDoc6(fichier, 1, 0, "", myError, myWarning)
Set swModel = swApp.ActivateDoc3(AssemblyTitle, True, swUserDecision, myError)
Set swAssembly = swModel
' Add the part to the assembly document
Set swcomponent = swAssembly.AddComponent5(fichier, swAddComponentConfigOptions_CurrentSelectedConfig, "", False, "", 0, 0, 0)
End Sub
het werkt, maar ik moest de "SldWorks.ModelDoc2" vervangen door "object"
Denk je dat ik hetzelfde zou kunnen doen, maar dan van wat er in het perspapier is opgeslagen? Als ik bijvoorbeeld een nummer kopieer, wordt het geopend met de macro (als het bestaat natuurlijk)? Waar kan ik de waarde van het klembord krijgen?
Sub ouvrirdanssolidworks()
Dim swApp As Object 'ici
Dim swModel As Object 'ici SldWorks.ModelDoc2
Dim myError As Long
Dim myWarning As Long
Dim swAssembly As Object 'ici SldWorks.ModelDoc2
Dim fichier As String
Dim swcomponent As Object 'ici SldWorks.Component2
Set swApp = CreateObject("SldWorks.Application")
If swApp.GetDocumentCount = 0 Then
MsgBox "Aucun fichier ouvert"
Set swApp = Nothing
End If
Set swModel = swApp.ActiveDoc
AssemblyTitle = swModel.GetTitle
a = ActiveCell.Value
b = "C:\EPDM_VAULT1\1 000 00x-Fournitures\"
c = 1
d = Val(Right(ActiveCell.Value, 3))
e = Left(ActiveCell.Value, 6)
If Val(Right(ActiveCell.Value, 3)) > 499 Then c = 2
If c = 1 Then fichier = "C:\EPDM_VAULT1\1 000 00x-Fournitures\" & e & "000-" & e & "499\" & a & ".sldprt"
If c = 2 Then fichier = "C:\EPDM_VAULT1\1 000 00x-Fournitures\" & e & "500-" & e & "999\" & a & ".sldprt"
Set swModel = swApp.OpenDoc6(fichier, 1, 0, "", myError, myWarning)
'If c = 1 Then fichier = "C:\EPDM_VAULT1\1 000 00x-Fournitures\" & e & "000-" & e & "499\" & a & ".prt"
'If c = 2 Then fichier = "C:\EPDM_VAULT1\1 000 00x-Fournitures\" & e & "500-" & e & "999\" & a & ".prt"
'Set swModel = swApp.OpenDoc6(fichier, 1, 0, "", myError, myWarning)
extensionTitle = swApp.ActiveDoc.GetTitle
Set swModel = swApp.ActivateDoc3(AssemblyTitle, True, swUserDecision, myError)
Set swAssembly = swModel
' Add the part to the assembly document
Set swcomponent = swAssembly.AddComponent5(extensionTitle, swAddComponentConfigOptions_CurrentSelectedConfig, "", False, "", 0, 0, 0)
End Sub
@Yves.T: niet verkeerd, ik geef alleen een link aan naar de methode om toegang te krijgen tot het klembord. Het is aan elke persoon om zich aan te passen aan zijn behoeften.