vb引用excel后仍提示用户定义类型未定义
代码如下PrivateSubCommand1_Click()Dimz1,z2,z5AsIntegerDimi,m,n,a,P,n1,n6,n16,TAsDoublei=V...
代码如下
Private Sub Command1_Click()
Dim z1, z2, z5 As Integer
Dim i, m, n, a, P, n1, n6, n16, T As Double
i = Val(Text2.Text)
P = Val(Text1.Text)
n = Val(Text4.Text)
m = Val(Text3.Text)
Dim k As Integer
Dim xlapp As Excel.Applocation
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim FileName1, SheetName As String
FileName1 = "D:\data.xls"
SheetName = "sheet1"
Set xlapp = CreateObject("Excel.Application")
Set xlBook = xlapp.Workbooks.open(FileName1)
xlapp.Visible = ture
Set xlSheet = xlBook.Worksheets(SheetName)
For z1 = 17 To 100
For z2 = Int(z1 * 1.5) To 150
z5 = (i - 1) * z1 / z2
n1 = (z5 / (z5 - 1) - 1) * (z5 / (z5 - 1) - 0.998 + z2 * z5 * 0.992 / (z1 * (z5 - 1)))
n6 = (z5 / (z5 - 1) - 0.998) * ((z5 / (z5 - 1) - 1 + z2 * z5 / (z1 * (z5 - 1))))
n16 = n1 / n6
n3 = n16 * 0.99 ^ 3
T = 9550000 * P * n3 / n
a = m * (z1 + z2) / 2
If z5 Mod 2 = 0 Then
If 0.51 * (T ^ (1 / 3)) <= a And a <= 0.65 * (T ^ (1 / 3)) Then
k = k + 1
xlSheet.Cells(k, 1) = z1
xlSheet.Cells(k, 2) = z2
xlSheet.Cells(k, 3) = z5
xlSheet.Cells(k, 4) = n3
xlSheet.Cells(k, 5) = T
xlSheet.Cells(k, 6) = 1 + (z2 / z1) * z5
End If
End If
Next z2
Next z1
xlBook.SaveAs FileName:=FileName1
xlBook.Close
xlapp.Quit
Set slApp = Nothing
End Sub 展开
Private Sub Command1_Click()
Dim z1, z2, z5 As Integer
Dim i, m, n, a, P, n1, n6, n16, T As Double
i = Val(Text2.Text)
P = Val(Text1.Text)
n = Val(Text4.Text)
m = Val(Text3.Text)
Dim k As Integer
Dim xlapp As Excel.Applocation
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim FileName1, SheetName As String
FileName1 = "D:\data.xls"
SheetName = "sheet1"
Set xlapp = CreateObject("Excel.Application")
Set xlBook = xlapp.Workbooks.open(FileName1)
xlapp.Visible = ture
Set xlSheet = xlBook.Worksheets(SheetName)
For z1 = 17 To 100
For z2 = Int(z1 * 1.5) To 150
z5 = (i - 1) * z1 / z2
n1 = (z5 / (z5 - 1) - 1) * (z5 / (z5 - 1) - 0.998 + z2 * z5 * 0.992 / (z1 * (z5 - 1)))
n6 = (z5 / (z5 - 1) - 0.998) * ((z5 / (z5 - 1) - 1 + z2 * z5 / (z1 * (z5 - 1))))
n16 = n1 / n6
n3 = n16 * 0.99 ^ 3
T = 9550000 * P * n3 / n
a = m * (z1 + z2) / 2
If z5 Mod 2 = 0 Then
If 0.51 * (T ^ (1 / 3)) <= a And a <= 0.65 * (T ^ (1 / 3)) Then
k = k + 1
xlSheet.Cells(k, 1) = z1
xlSheet.Cells(k, 2) = z2
xlSheet.Cells(k, 3) = z5
xlSheet.Cells(k, 4) = n3
xlSheet.Cells(k, 5) = T
xlSheet.Cells(k, 6) = 1 + (z2 / z1) * z5
End If
End If
Next z2
Next z1
xlBook.SaveAs FileName:=FileName1
xlBook.Close
xlapp.Quit
Set slApp = Nothing
End Sub 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询