Dim swApp As Object
& ?1 A$ d2 d, p2 g2 n' GDim Part As Object
9 |! t/ r G9 h* ?Dim sldPath As String
6 r% C6 S6 [9 N( Y g* ]9 Z5 ?/ d5 S( x. ?2 C
Dim boolstatus As Boolean
: S# y# i7 m4 DDim longstatus As Long, longwarnings As Long7 t! y( b w, O: ?; q, x
4 ^9 ?' g/ |# N1 e" X
, x, E- i$ w! [& W4 j
- q: R: h- a* l$ r# k
* e+ H$ o' x+ a# c% j/ s6 qSub Test()5 t1 p8 _- s3 B3 T% ?! e
Set swApp = Application.SldWorks
. X# o+ U2 p, q0 |$ c/ JsldPath = "C:\Users\kbisi\Desktop\实验\" '设定目录 T* Q T% i# t* {
, F. ?$ J) ~, c5 m+ SswFileName = Dir(sldPath & "*.sld*") '搜寻首个零件档案名称
5 Q8 S9 T: } @0 IIf UCase(Right(swFileName, 3)) = "PRT" Then swFileTYpe = 1
. @/ G! n3 G$ x9 o# Q. Q% M- iIf UCase(Right(swFileName, 3)) = "ASM" Then swFileTYpe = 24 I. f# L, K; ^1 M
( P5 u% g8 j: W9 Z8 xDo While swFileName <> ""7 h/ s5 O3 i* U8 r9 c" ]
* I0 b* u" L9 i7 Q! ~3 l. W$ a( ISet swApp = Application.SldWorks
9 p( E* Q& z; `
9 e e( e% b5 D& W$ Z7 ^'Set swDoc = swApp.OpenDoc(sldPath & swFileName, swFileTYpe) '开启零件
5 M' U0 K) Q' j+ w* S6 N/ W8 i) @5 ]- M ]& S, m+ J# j6 p( J
Set swModel = swApp.OpenDoc6(sldPath & swFileName, swFileTYpe, swOpenDocOptions_Silent, "", longstatus, longwarnings)0 ?' j& h2 `. E H' V* m
5 o! j9 y6 |8 h. [+ c) t2 @ F
+ A t: g) ~& T# o
+ {; d( w5 a1 Q. b5 g; W4 h
. l4 B2 p1 O0 t0 l
0 w w& b& @2 \( L, `: k$ ySet Part = swApp.ActiveDoc
" @& [; [9 A4 u4 _8 _9 g( V3 n! R7 w# j
Call plmain
1 y$ o& ~( i G2 T+ X6 ^- i8 w9 c) H" D/ G0 |$ o. W0 o( ]
# @) o& U* I2 u( S4 t
'
* p6 R0 H; W) r" ]5 ?. V3 N6 f6 g- e! n3 m' @
8 |, v% y' y* [. `
3 |! q+ w8 y4 o. \/ N% YPart.Save '保存%
0 w- n; f$ I2 f+ \7 |swApp.CloseDoc (swFileName) '关闭零件0 `5 p$ g* u I( E8 Z
1 ^# {6 ?; O% H: `5 I' r
If swFileName = "" Then Exit Do
; h5 w' r8 f' X( _7 k* z' e/ X
% _/ {8 E8 B' @# a+ `) S! z# N2 p. V4 H" u2 _# R
swFileName = Dir '搜寻下一个零件档案名称0
" r4 f3 w( q- |! [ X& c
: J* g9 n# J( s$ o8 n" |Loop '循环搜寻5 U3 w& v) p" V
End Sub
6 v4 R- B# {6 }8 }按F8一行看程序错误为什么老是跳过Then swFileTYpe = 2 |