明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2713|回复: 0

[求助]EXCEL不能另存?

[复制链接]
发表于 2008-1-19 17:14:00 | 显示全部楼层 |阅读模式

前几天我搞了一个小VBA宏,作用是把在ACAD中获取的一些数据通过一些计算,然后输入到EXCEL模板文件中,再另存。由于进行了多次调试,后来竟发现不能正常另存(起先是可以的),具体症状是:运行到另存这条语句时,似乎跳到了某个陷阱中,总是运行不结束,当然也不报错。想请各位前辈分析分析,是怎么回事,先谢谢了!

代码粘贴如下:

Private Sub CommandButton1_Click()
UserForm1.Hide

Dim cir As AcadRegion: Dim li As Double: Dim lili As Double 'li=面域周长 lili=合计面域周长
Dim th(0 To 6) As Double: Dim opo As Integer   'opo=小孔数

Dim i As Integer
Dim plate As Integer: plate = 6
Dim ty As String:  ty = "冲修"   'ty = 模具类型
'Dim path1 As String
'path1 = ThisDrawing.Path       'path1 = 文件另存路径
th(0) = CDbl(TextBox1.Text)
th(1) = CDbl(TextBox2.Text)
th(2) = CDbl(TextBox3.Text)
th(3) = CDbl(TextBox4.Text)
th(4) = CDbl(TextBox5.Text)
th(5) = CDbl(TextBox6.Text)
th(6) = 56

 

 

Dim ExcelApp As New Excel.Application
ExcelApp.Workbooks.Open "f:\工作目录\btl\成本预算\temp\线割加工单.xls"
With ExcelApp.ActiveWorkbook.Worksheets("sheet1")
.Range("c" & 9) = TextBox7.Text
.Range("g" & 9) = TextBox8.Text
.Range("b" & 11) = "凸凹模"
.Range("b" & 12) = "内退料"
.Range("b" & 13) = "外退料"
.Range("b" & 14) = "下垫板"
.Range("b" & 15) = "凹模"
.Range("b" & 16) = "上固板"
.Range("b" & 17) = "异形冲头"


If OptionButton2.Value = True Then
th(2) = 40
plate = 3: ty = "翻边"
.Range("b" & 11) = "凹模"
.Range("b" & 12) = "退料板"
.Range("b" & 13) = "凸模"
.Range("b" & 14) = "上固板"
.Range("b" & 15) = ""
.Range("b" & 16) = ""
.Range("b" & 17) = ""
.Range("b" & 18) = ""


ElseIf OptionButton3.Value = True Then
th(2) = 40
plate = 3: ty = "包胎"
.Range("b" & 11) = "凹模"
.Range("b" & 12) = "退料板"
.Range("b" & 13) = "凸模"
.Range("b" & 14) = "上固板"
.Range("b" & 15) = ""
.Range("b" & 16) = ""
.Range("b" & 17) = ""
.Range("b" & 18) = ""
End If
.Range("k" & 9) = ty


Dim sset As AcadSelectionSet '定义选择集


On Error Resume Next

For ii = 0 To plate
Set sset = ThisDrawing.SelectionSets.Add("sz4")
Dim FilterType(0) As Integer: Dim FilterData(0) As Variant
FilterType(0) = 0: FilterData(0) = "region" '过滤条件
sset.SelectOnScreen FilterType, FilterData

opo = 0: lili = 0

For Each cir In sset

 

li = cir.Perimeter
cir.color = 2
If li < 1000 / th(i) Then
cir.color = 4
li = 0
opo = opo + 1
End If
lili = lili + li

Next

sset.Delete

 

.Range("d" & 11 + i) = th(i)
.Range("e" & 11 + i) = opo
.Range("g" & 11 + i) = lili
i = i + 1


Next ii

 End With

ExcelApp.ActiveWorkbook.SaveAs "d:\book2.xls" '(path1 & "\" & TextBox8.Text & ty & ".xls")
 
 ExcelApp.Workbooks.Close
 ExcelApp.Quit
 ThisDrawing.Application.Update

End Sub

 以下是源码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-22 20:03 , Processed in 0.179292 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表