Dim swApp As Object# o. N5 _- s7 E
Dim Part As Object+ _$ S/ F+ s* D; {7 C
Dim sldPath As String
% Z& P9 f$ w0 {2 @
) L+ ?) z+ Z1 d* xDim boolstatus As Boolean: s# f1 `/ c4 ]0 E
Dim longstatus As Long, longwarnings As Long
Q% S" U, v* x3 C* x( U8 n2 H+ W- _+ V, I
: O' H& P& L- |. x ]% B8 o
$ ~! C* q3 Q! M0 b- _4 h8 \" u% z9 N5 R* k+ w* o* @+ U
Sub Test()# ]; e& J( u1 P) A1 {' K/ k, @
Set swApp = Application.SldWorks
4 E6 D( J. Y( n0 k" GsldPath = "C:\Users\kbisi\Desktop\实验\" '设定目录# X' B- j5 E' `) |0 d
: i- l3 \* d7 W9 Z# i+ S# SswFileName = Dir(sldPath & "*.sld*") '搜寻首个零件档案名称! |# p, b' z3 L& ?% E8 U
If UCase(Right(swFileName, 3)) = "PRT" Then swFileTYpe = 1
9 k7 @1 r3 P; UIf UCase(Right(swFileName, 3)) = "ASM" Then swFileTYpe = 29 S& `1 s' k1 C, R4 Y
+ m" H* d/ ` I) n6 Q3 eDo While swFileName <> ""
9 W# u: O* v+ @, Y! @2 K# `! C9 Z( ^* e
Set swApp = Application.SldWorks
/ U' O. F( D; P: V
( C5 f7 C( [, `# L. U) `0 i'Set swDoc = swApp.OpenDoc(sldPath & swFileName, swFileTYpe) '开启零件( b& f4 u6 Q+ ^* c
4 `, \9 _( m/ W0 e' u. tSet swModel = swApp.OpenDoc6(sldPath & swFileName, swFileTYpe, swOpenDocOptions_Silent, "", longstatus, longwarnings)
7 d4 t, `4 o& [; M
! f" h. Z$ k$ Z4 s0 ~; S
4 }9 h! q/ N7 G1 C1 k/ d, I4 d
) Y/ g U2 C& `7 F3 i3 s. S' O" t
6 V& h. Z+ Q8 y
Set Part = swApp.ActiveDoc8 H8 Y8 }$ B0 Y" B
6 P w0 E8 X7 G; z S) SCall plmain
+ D: B, u5 M* s+ w/ v2 f. f8 J5 s0 x8 Y- \4 K7 _
' ]; D1 C" i5 C# M ^') l! w7 ? r6 A3 V% S% A6 b( }
& I/ j: [; a! Y5 g
9 H. B9 y$ Z; k4 i1 C7 t! m7 I3 U. b% M7 m6 l( Q7 V
Part.Save '保存%# g' i' I7 f* B+ }; p) I6 ?+ q0 T
swApp.CloseDoc (swFileName) '关闭零件
. [# N1 a$ B5 l. }0 c- n5 V5 a9 n$ P* Y7 |0 u9 e+ @2 ~' V% ~! i, I U
If swFileName = "" Then Exit Do5 `$ C# w7 z5 X3 q. O
, k: [6 k5 g A# J* X; @
. Q# U6 g% U" R3 S; |swFileName = Dir '搜寻下一个零件档案名称04 p* N0 t5 \$ L
+ @& r# R% s1 d$ iLoop '循环搜寻0 v" |3 H& h2 S: \
End Sub
$ [/ x, V7 V r; e' n4 Q/ F" i9 {按F8一行看程序错误为什么老是跳过Then swFileTYpe = 2 |