Dim swApp As Object% T% @$ k1 X9 e3 s, x
Dim Part As Object6 Z; ?4 c* I: A' l l. Y
Dim sldPath As String+ T2 b4 v, U& r' R' [5 G4 o
# h( F( U+ l# ^5 Q7 P7 ?
Dim boolstatus As Boolean
9 y3 k# X! s1 C3 m1 S! f) C& C2 [Dim longstatus As Long, longwarnings As Long
u$ u3 V! O& ~6 h" J0 E, h% C# F* `# c& ^6 Z p# D2 z8 x
6 h2 _; x7 k+ I% e+ J8 x
) v% W+ L* d3 b+ i$ [, E2 X2 D8 ^ M* s: K5 d# C5 ?& e
Sub Test()
W; O) P! K9 ]6 |Set swApp = Application.SldWorks ^' w* y! G* L C, M
sldPath = "C:\Users\kbisi\Desktop\实验\" '设定目录
8 m3 q V) x* [1 `5 l( j( e8 C0 @2 o( `9 i# `- \. j! W6 v
swFileName = Dir(sldPath & "*.sld*") '搜寻首个零件档案名称4 B/ o4 e, q. b/ P2 M0 e. C ^
If UCase(Right(swFileName, 3)) = "PRT" Then swFileTYpe = 1) r! O. G! W( _
If UCase(Right(swFileName, 3)) = "ASM" Then swFileTYpe = 2
0 ~7 I* G7 M2 ?. C; C
3 f M8 I8 ]# l( Z/ p6 {Do While swFileName <> ""1 x4 [5 h8 ], }) W( O9 o% A/ y
# v; I. u% S4 c: O( A0 r8 m( _. zSet swApp = Application.SldWorks
. X+ c9 I1 ]7 u9 B
& J( D$ Y% f# Z( U2 k'Set swDoc = swApp.OpenDoc(sldPath & swFileName, swFileTYpe) '开启零件& Z/ r) E+ n2 f
) B& C6 |% V( ~% w' p# D* HSet swModel = swApp.OpenDoc6(sldPath & swFileName, swFileTYpe, swOpenDocOptions_Silent, "", longstatus, longwarnings)! [% P6 z/ G8 |/ q0 E
' p1 F$ k* @" s$ O" B- G. e1 f# ?) K! `+ y
/ W0 H! [5 ^1 T# V, V
% J4 }+ @7 T3 u W7 I
( L9 c% w! X" u9 @! P J, C: L
Set Part = swApp.ActiveDoc( S+ s- d8 e; M" E% w! }
2 e, f) m3 l8 Z I" d
Call plmain
' m' _: U4 O4 W( Y4 o m# \; X
5 `! z1 Q& W6 m
9 \) D7 o @# x% _: A'
+ ?) q' v1 \6 R# m% K& C
9 p! K7 i- c) G% x* a5 I- e% [9 `; t# Q2 _1 j. o
* M. m5 _4 F- mPart.Save '保存%+ C% B% i, F$ C: f9 z- M
swApp.CloseDoc (swFileName) '关闭零件5 h6 |; j2 i: p9 ^
8 d7 a+ `. p2 e' q( |If swFileName = "" Then Exit Do
' [ s7 y9 L4 z9 d+ K# H4 p" W8 ]' A/ N
: v3 [& t! z) z* Q- W
swFileName = Dir '搜寻下一个零件档案名称02 F$ W2 E2 b6 a1 ~. W! Z5 A( _
, s" I: n2 R* n4 d$ C
Loop '循环搜寻: \ o" f$ n1 W; v
End Sub
( N4 o( y3 y% M) D$ K+ o6 a$ @按F8一行看程序错误为什么老是跳过Then swFileTYpe = 2 |