Dim swApp As Object
- i) u( ]& G1 GDim Part As Object4 U J U* _+ d( K6 K
Dim sldPath As String2 p/ F" g0 ]- b' r9 h8 y6 q
# g8 {* A( f+ Q1 W9 K+ N+ l
Dim boolstatus As Boolean
$ x& f6 s1 a+ ]' Z! Y0 @0 fDim longstatus As Long, longwarnings As Long( G( F( e ^" u; f& k
' s# d) u* X4 z8 ~
$ U; _: f" O$ B3 e; N' G$ w9 `# H; J/ }( o# J
( Y u) T* A/ ]: J% W- w
Sub Test()# F* h+ y2 T, E3 e; z& @& G
Set swApp = Application.SldWorks0 \' b, r- L& I) e D) Z# P( C
sldPath = "C:\Users\kbisi\Desktop\实验\" '设定目录
3 ?" t, T* e' B; k5 p1 [+ _7 K3 ~7 ?4 Y! ^- {' f! B
swFileName = Dir(sldPath & "*.sld*") '搜寻首个零件档案名称3 F+ f- P7 ]; Z# m2 {0 T& }4 d
If UCase(Right(swFileName, 3)) = "PRT" Then swFileTYpe = 1
4 R3 R- J g3 |; e! JIf UCase(Right(swFileName, 3)) = "ASM" Then swFileTYpe = 2
: ~6 a. v# p# A" K, ?) D) Y% ~! E" n! {/ K1 c
Do While swFileName <> ""
9 f: Y* K$ h5 X' {6 s4 k
6 ^( r$ P. _$ R+ w: M2 w1 |9 G% WSet swApp = Application.SldWorks# B& y+ D1 O* [! N
9 X5 R2 G7 X$ c'Set swDoc = swApp.OpenDoc(sldPath & swFileName, swFileTYpe) '开启零件5 t& D, w4 S `' V, W
+ M7 q0 q+ b* d8 Y" p
Set swModel = swApp.OpenDoc6(sldPath & swFileName, swFileTYpe, swOpenDocOptions_Silent, "", longstatus, longwarnings)
. T5 t. T/ _3 p
. h$ M) R; P9 _- B: C, ?0 j; t
2 X0 Z4 s! C6 O6 ~" U1 |7 o' A# C
# w, U6 r/ l- J. G4 T# M4 M1 f0 B1 X! g( ~% a O
Set Part = swApp.ActiveDoc- o r- g( b7 n% D, d H3 h
{* o7 t# ~; @. p0 |7 z& ]Call plmain7 F" J" \& N, H5 F: L
2 J) h# w% w9 m1 _; s8 q, s" T' M) b7 N1 a5 s
'
/ c. J/ R8 f t1 l, F, q1 Q8 \$ e* A- m9 @; W' z! T, E* Q
/ `' R+ k2 N' D! e
4 B; {' R1 o$ m$ xPart.Save '保存%9 ~3 N% j- ^; d- `) _
swApp.CloseDoc (swFileName) '关闭零件
" ]! G9 u0 l0 y0 u- s: {" W
+ j5 O+ V$ q; l6 s7 i4 h1 rIf swFileName = "" Then Exit Do
- |: o% R5 n9 k. d* x; Q4 j e- a9 R% R9 m' ]: Y/ O
7 A% P6 ^. [, J# AswFileName = Dir '搜寻下一个零件档案名称0
9 y: l. o) n8 j7 N% O+ q8 `2 K' R% j
Loop '循环搜寻% V, [- j" A8 O0 P
End Sub+ m( A: E2 w; b. x! J0 `$ f a* }
按F8一行看程序错误为什么老是跳过Then swFileTYpe = 2 |