Dim swApp As Object8 B) C0 `1 ?0 Y. W0 d: r/ M
Dim Part As Object
( [# t, c! x+ v, fDim sldPath As String& ~. k. a y# p% K
$ A, g# c+ E+ H7 O* o# | g: fDim boolstatus As Boolean7 v6 @, W8 I: p0 D3 e, x3 ^. j
Dim longstatus As Long, longwarnings As Long8 s7 i) L/ W$ E8 J& M. \
* b* }0 ^ A/ r3 }
- G" C+ V: R# v( Q3 `
W: q+ U1 k" r; @( U3 \6 s8 Q S0 {
$ e6 \2 a7 m. g/ J+ r2 G9 h3 c- |Sub Test()3 [# U, j7 @$ \' i, ^& `2 w+ n
Set swApp = Application.SldWorks
. v; a/ h7 R0 S1 D0 hsldPath = "C:\Users\kbisi\Desktop\实验\" '设定目录0 F6 o5 u6 `/ f* q
! \9 L( _4 c: Z1 }8 K! }swFileName = Dir(sldPath & "*.sld*") '搜寻首个零件档案名称
$ Z* B2 A; \ q: d2 eIf UCase(Right(swFileName, 3)) = "PRT" Then swFileTYpe = 1
7 b2 l6 k/ a( h9 z9 {If UCase(Right(swFileName, 3)) = "ASM" Then swFileTYpe = 2; p- |) x* G+ k0 x0 g
?8 b: V7 ^* r2 B4 i8 z2 L
Do While swFileName <> ""
: d: _1 z3 m: u' F% w
: O( [: \: B; bSet swApp = Application.SldWorks) _& \" @- N7 U
2 m5 B7 R$ @& k; b" Y! U'Set swDoc = swApp.OpenDoc(sldPath & swFileName, swFileTYpe) '开启零件
9 L$ [& @6 O& @5 M2 q
$ v/ s: r( ^. a0 p8 s p6 _Set swModel = swApp.OpenDoc6(sldPath & swFileName, swFileTYpe, swOpenDocOptions_Silent, "", longstatus, longwarnings), t, N; I: E- [7 I& J* H0 z
0 N) e6 O0 k; P: a9 G) K( n& E: l7 e9 U4 C% P% ^1 q! a
s* r8 z0 @! Y( {7 T$ D' b
! @, S# Y/ Q/ {) Y+ h6 V
- B4 e8 `$ ?; C4 y& m: m' NSet Part = swApp.ActiveDoc
8 @$ O6 E K6 N4 n' J3 f0 F
5 ~4 u- _. ^ O# b1 V8 W# B! v2 VCall plmain- V& Y0 s+ R g# n5 @/ L, R
6 J( w! C' R7 w2 c1 f9 n
0 d: v9 X" g- j- M1 h/ a8 j'
5 T+ l( T& Z) X, w$ Q- Y; C3 o2 g) U* T' @! ?- r t& A$ F
) c+ F$ S2 N/ u
8 P9 i. d- g9 kPart.Save '保存%
* _6 n, i( A1 p' d9 m/ SswApp.CloseDoc (swFileName) '关闭零件% l$ s w' ~- f3 a# X4 W1 i
6 o! b2 r* A1 G0 D, ^9 J
If swFileName = "" Then Exit Do4 F0 ~& _& ?2 ~ Z. s
/ X: r# k# x! l4 f% \& H
0 Y+ ]' G s# Q1 n* R h
swFileName = Dir '搜寻下一个零件档案名称0, u7 x# G, f: f: q0 {( Z/ B5 ^4 j
; g0 _* H, r, e. x$ w) W# X. d0 S
Loop '循环搜寻. p6 b, f; }5 G# [ R
End Sub
; L9 V& J8 G; w按F8一行看程序错误为什么老是跳过Then swFileTYpe = 2 |