vb6.0操作excel

jiaxiaojiao 2012-06-18 07:36:59
本人下面的两个过程单独运行某一个能通过,若运行完一个(如command7)过程,再接着运行下一个就会出错,出错行我已经用红色字体显示,实时错误462:远程服务器不存在或不能使用。拜托高人指点一下,好久以来我都不知道怎么办,谢谢!每个过程的功能是:通过计算出Lmd和k的值,查表获得系数Rmx和Rmf的值。计算Lmd时我对结果进行了处理,调用EXcel的Floor函数。

Private Sub Command7_Click()
Set newApp = New Excel.Application
newApp.Visible = True
Set newBook = newApp.Workbooks.Open("g:/xi1.et")
Set newSheet = newBook.Worksheets(2)
Dim Rmx As Single

Dim Mx As Variant
Const pi = 3.14
q = pi * Val(Text9.Text) / Val(Text10.Text)
newBook.Worksheets(4).Activate
newBook.Worksheets(4).Cells(1, 1) = q
lmd = newApp.WorksheetFunction.Floor(Application.ActiveCell, 0.25) ‘调用EXCEL的工作表函数Floor
Text14.Text = lmd
k = Int(Val(Text6.Text) ^ 2 / (12 * 10 ^ (-5)) / Val(Text9.Text) ^ 2 + 0.5)
Text15.Text = k
newBook.Worksheets(2).Activate
For i = 2 To 9
For j = 2 To 29
If k = newSheet.Cells(1, j).Value Then
o = j
End If
Next D
If lmd = newSheet.Cells(i, 1).Value Then
p = i
End If
Next c
Rmx = newSheet.Cells(p, o).Value

Text16.Text = Rmx
Mx = 0.65 * Val(Text1.Text) * Val(Text16.Text) / Val(Text6.Text) / Val(Text10.Text)
Text11.Text = Mx
Set newSheet = Nothing
newBook.Close
Set newBook = Nothing
newApp.Quit
Set newApp = Nothing
Shell "cmd.exe /c taskkill /f /im excel.exe"
End Sub


Private Sub Command10_Click()
Set newApp = CreateObject("Excel.Application")
newApp.Visible = True
Set newBook = newApp.Workbooks.Open("g:/Rmf.et")
Set newSheet = newBook.Worksheets(1)
Dim Rmf As Single
Dim Mf As Variant
Const pi = 3.14
q = pi * Val(Text9.Text) / Val(Text10.Text)
newBook.Worksheets(3).Activate
newBook.Worksheets(3).Cells(1, 1) = q
lmd = newApp.WorksheetFunction.Floor(Application.ActiveCell, 0.25) ‘调用EXCEL的工作表函数Floor
k = Int(Val(Text6.Text) ^ 2 / (12 * 10 ^ (-5)) / Val(Text9.Text) ^ 2 + 0.5)
newBook.Worksheets(1).Activate
Set newSheet = newBook.Worksheets(1)
For i = 2 To 9
For j = 2 To 29
If k = newApp.Cells(1, j).Value Then
n = j
End If
Next j
If lmd = newApp.Cells(i, 1).Value Then
m= i
End If
Next i
Rmf = newApp.Cells(m, n).Value
Text17.Text = Rmf
Mf = 0.65 * Val(Text1.Text) * Rmf / Val(Text6.Text) / Val(Text10.Text)
Text12.Text = Mf
newBook.Close
Set newBook = Nothing
newApp.Quit
Set newApp = Nothing
Shell "cmd.exe /c taskkill /f /im excel.exe"
End Sub
...全文
146 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

742

社区成员

发帖
与我相关
我的任务
社区描述
VB 版八卦、闲侃,联络感情地盘,禁广告帖、作业帖
社区管理员
  • 非技术类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧