Dim swApp As Object8 [4 o/ j! \, a% T6 D, I# y
Dim Part As Object3 O$ U3 ^0 M% F
Dim sldPath As String% ^5 u! y# C( q, c9 a
$ y& v- ?6 `. F
Dim boolstatus As Boolean
- [! {! v. w0 A' z wDim longstatus As Long, longwarnings As Long
. V" b/ ^4 R$ f5 o ?' Y; k* K
: ^- s" i* G; a' T) O4 U) y' W: s! z' D: ?; a
( E4 @6 y* G' d: t4 r
& A* e+ ^2 N( f9 [0 M6 o3 }
Sub Test()) z7 V5 B4 J1 u2 s+ w
Set swApp = Application.SldWorks2 t! _, q5 H! U9 g3 u" M5 H
sldPath = "C:\Users\kbisi\Desktop\实验\" '设定目录
3 K. L$ |/ a& d' u- z4 }
+ @6 O9 t& P& T! S: tswFileName = Dir(sldPath & "*.sld*") '搜寻首个零件档案名称& O6 w8 H0 b0 F) _; w1 G# _$ q
If UCase(Right(swFileName, 3)) = "PRT" Then swFileTYpe = 1
. `$ g$ o: L5 m# {If UCase(Right(swFileName, 3)) = "ASM" Then swFileTYpe = 2& ] O! L( s' T8 A6 X- p
/ {) C. ` w; [0 M( X, z6 ADo While swFileName <> ""& F) ]8 k! ~6 Q9 g( g1 ^, {
& f6 |* K. \) n* d, h) l
Set swApp = Application.SldWorks9 c3 S" k0 {" F
) g4 ] o t1 `$ W
'Set swDoc = swApp.OpenDoc(sldPath & swFileName, swFileTYpe) '开启零件1 r% m) s) [. Y1 h K; m
1 i% r5 [3 E6 `% W% r' S5 H: RSet swModel = swApp.OpenDoc6(sldPath & swFileName, swFileTYpe, swOpenDocOptions_Silent, "", longstatus, longwarnings); m" u, {, }3 }9 a
1 U! O* a& c0 o4 L. j2 ~
7 V3 F& J" `. [
% B( N) h" d: N# g6 I
3 ?) U/ j) z# `% n# b. e, a7 Z- S( M& j+ K4 B5 a6 _" B: \
Set Part = swApp.ActiveDoc
6 M2 S+ V2 @& F; y V- p* g5 V5 Y# K5 [
- V/ ?) x0 G# P, a4 F. BCall plmain
* V7 X% {& t! g, B% d9 S2 @+ B* Z& `0 ]& d, D6 u
3 }- [9 s/ `/ U _# F- }'
" i7 _ ~- O c- B, x5 F( A
5 W, s" D7 f. ]( F8 ]6 `) A" `. [+ o/ G* k, j$ p& X+ q6 [: f
- U. ~/ Q6 }% V) z
Part.Save '保存%; b' E) @8 f# u
swApp.CloseDoc (swFileName) '关闭零件- w5 ]9 L9 f& X/ ?# _
6 L# n0 E7 F' F2 eIf swFileName = "" Then Exit Do
+ o0 m( n* K& ~, p- S. z; g
$ H5 v: r' Y* w
3 |6 h2 }# F0 G9 F2 H" n. h% pswFileName = Dir '搜寻下一个零件档案名称0
, c$ t, e; N, _
+ C" O, A* Q' a' o0 kLoop '循环搜寻
: [7 m+ Y1 G% ^6 i/ h) |5 a' yEnd Sub |