Dim swApp As Object
5 T$ j& v1 J/ t1 _Dim Part As Object
" U" O( @) e, {3 |8 s3 @# {; c% IDim sldPath As String
. y( u$ K( W# J3 E# ~4 L; I0 u' e; A" ~; T- A& P; Y$ |' K! s
Dim boolstatus As Boolean
; q: L5 \; G) w/ Q3 k% wDim longstatus As Long, longwarnings As Long
1 `: D, k1 k0 o. H6 z+ e8 S1 {+ E& ^
" y5 ~+ {0 d. b: h$ M: [
, W- _6 k6 `. n1 z9 s5 H" z5 c% Q- i) N' K! v' D5 [: d
Sub Test()1 u: S( g$ r7 D, g+ M
Set swApp = Application.SldWorks
8 p( ]$ L# O3 z a6 X! zsldPath = "C:\Users\kbisi\Desktop\实验\" '设定目录
- r) B: R: c, |2 ^& x
- M. n; M) n, N6 d: WswFileName = Dir(sldPath & "*.sld*") '搜寻首个零件档案名称
w) {6 [+ v$ v* n/ U/ e" oIf UCase(Right(swFileName, 3)) = "PRT" Then swFileTYpe = 1
! a3 y/ }* |, i! K" VIf UCase(Right(swFileName, 3)) = "ASM" Then swFileTYpe = 2
% L( h- ], [0 U0 ^0 l" C% T2 t+ l& N( Z# k# H) y
Do While swFileName <> ""
2 U" O4 f: R2 _* [
# c. k5 t$ [8 L6 l$ S0 D% hSet swApp = Application.SldWorks: m+ h% k5 x2 ?* P: z; x3 J8 I
& {( i. v8 ]. ~3 M
'Set swDoc = swApp.OpenDoc(sldPath & swFileName, swFileTYpe) '开启零件
( N0 P( s$ [' H4 n- U
5 Z9 q/ ^- _2 ZSet swModel = swApp.OpenDoc6(sldPath & swFileName, swFileTYpe, swOpenDocOptions_Silent, "", longstatus, longwarnings). U O8 k8 a# Q4 v* g3 h
( T! \; l8 B) p; ^+ c) D
* E9 |9 H& |1 J: \5 Z9 r' t" {, c# q
6 _! h/ O$ q. T+ f3 z! D* k6 N
. e1 t8 b9 s( g) U( J
Set Part = swApp.ActiveDoc
7 p _9 u" @4 ~/ o% W
N& d( [5 h% F% F s, ?0 kCall plmain' [1 s( s, [0 h- ~9 \3 G
* J1 C% s3 }% C
$ A) q/ I2 C2 l& \' r'
& [% i P% c" b% H8 @6 A
# ^# @; [8 g7 {+ k4 ]; p5 \' Y: Y( a; V4 b
" x J# z( F9 D& ~3 m; ]+ ]% APart.Save '保存%
/ e S, r [4 k- D/ BswApp.CloseDoc (swFileName) '关闭零件0 o+ f0 I& I" z: q& E+ z& u
% \- l5 g% X. FIf swFileName = "" Then Exit Do
& k2 _4 b9 O- x
, o% D4 o- h; T9 t4 y( J3 N0 l
5 n1 l! U0 l' n) m9 L2 R9 X5 I, y) xswFileName = Dir '搜寻下一个零件档案名称0! t3 R" J% z, p+ {! h2 \4 e
: N0 b0 z$ i" DLoop '循环搜寻0 V1 O. T4 i# a6 k- E
End Sub2 Y/ Z- F% ^+ r8 C+ E
按F8一行看程序错误为什么老是跳过Then swFileTYpe = 2 |