执行语句Set ExcelApp = CreateObject("Excel.Application") 时,总提示:ActiveX 部件不能创建对象: 'Excel.Application'
请问,哪位有碰到过这种情况吗?应如何解决,请指教。谢谢。
6 个解决方案
#1
机器上有没有装excel
#3
在窗体最上面工程引用 , 把它打勾即可.
#4
没装office的,只装了wps的。
谢谢Veron_04
cbm666:这个引用我找不到。555。。。。
#5
那你试这个 自定义 Excell
c:\tt.xls 改为你自己的路径与文件名
Option Explicit
Dim vbexcel11 As Object
Dim vbbook As Object
Dim Rownum%, str1$, str2$, str3$, str4$, len1%, len2%, len3%, CC$
Private Sub Form_Load()
Set vbexcel11 = CreateObject("Excel.Application") '创建excel对象
vbexcel11.Visible = True '对象可见
Set vbbook = vbexcel11.Workbooks.Open("c:\tt.xls") '打开文件
Me.Caption = "Excell 读取"
End Sub
Private Sub Command1_Click()
Me.Caption = "读取中,请稍侯...."
Rownum = 1
Me.Cls
Do Until vbexcel11.Sheets(1).Cells(Rownum, 1) = "" And vbexcel11.Sheets(1).Cells(Rownum, 2) = ""
DoEvents
str1 = vbexcel11.Sheets(1).Cells(Rownum, 1): str2 = vbexcel11.Sheets(1).Cells(Rownum, 2)
str3 = vbexcel11.Sheets(1).Cells(Rownum, 3): str4 = vbexcel11.Sheets(1).Cells(Rownum, 4)
'每个字段最长为15位,为了对齐要补空格,中文字占两位.
len1 = CBMstrLen(str1): len2 = CBMstrLen(str2): len3 = CBMstrLen(str3)
str1 = IIf(len1 > 15, CBMmid(str1, 1, 15), str1)
str2 = IIf(len2 > 15, CBMmid(str2, 1, 15), str2)
str3 = IIf(len3 > 15, CBMmid(str3, 1, 15), str3)
Print Trim(str1) & Space(15 - IIf(len1 >= 15, 15, len1)) & Trim(str2) & Space(15 - IIf(len2 >= 15, 15, len2)) & Trim(str3) & Space(15 - IIf(len3 >= 15, 15, len3)) & Trim(str4)
Rownum = Rownum + 1
Loop
Me.Caption = "Excell 读取"
MsgBox "READ OK"
End Sub
Public Function CBMmid(ByVal Tstr As String, Start As Integer, Optional leng As Variant) As String
CC = IIf(IsMissing(leng), StrConv(MidB(StrConv(Tstr, vbFromUnicode), Start), vbUnicode), StrConv(MidB(StrConv(Tstr, vbFromUnicode), Start, leng), vbUnicode))
CBMmid = CC
End Function
Public Function CBMstrLen(Wstr$) As Long
CBMstrLen = LenB(StrConv(Wstr, vbFromUnicode))
End Function
c:\tt.xls 改为你自己的路径与文件名
Option Explicit
Dim vbexcel11 As Object
Dim vbbook As Object
Dim Rownum%, str1$, str2$, str3$, str4$, len1%, len2%, len3%, CC$
Private Sub Form_Load()
Set vbexcel11 = CreateObject("Excel.Application") '创建excel对象
vbexcel11.Visible = True '对象可见
Set vbbook = vbexcel11.Workbooks.Open("c:\tt.xls") '打开文件
Me.Caption = "Excell 读取"
End Sub
Private Sub Command1_Click()
Me.Caption = "读取中,请稍侯...."
Rownum = 1
Me.Cls
Do Until vbexcel11.Sheets(1).Cells(Rownum, 1) = "" And vbexcel11.Sheets(1).Cells(Rownum, 2) = ""
DoEvents
str1 = vbexcel11.Sheets(1).Cells(Rownum, 1): str2 = vbexcel11.Sheets(1).Cells(Rownum, 2)
str3 = vbexcel11.Sheets(1).Cells(Rownum, 3): str4 = vbexcel11.Sheets(1).Cells(Rownum, 4)
'每个字段最长为15位,为了对齐要补空格,中文字占两位.
len1 = CBMstrLen(str1): len2 = CBMstrLen(str2): len3 = CBMstrLen(str3)
str1 = IIf(len1 > 15, CBMmid(str1, 1, 15), str1)
str2 = IIf(len2 > 15, CBMmid(str2, 1, 15), str2)
str3 = IIf(len3 > 15, CBMmid(str3, 1, 15), str3)
Print Trim(str1) & Space(15 - IIf(len1 >= 15, 15, len1)) & Trim(str2) & Space(15 - IIf(len2 >= 15, 15, len2)) & Trim(str3) & Space(15 - IIf(len3 >= 15, 15, len3)) & Trim(str4)
Rownum = Rownum + 1
Loop
Me.Caption = "Excell 读取"
MsgBox "READ OK"
End Sub
Public Function CBMmid(ByVal Tstr As String, Start As Integer, Optional leng As Variant) As String
CC = IIf(IsMissing(leng), StrConv(MidB(StrConv(Tstr, vbFromUnicode), Start), vbUnicode), StrConv(MidB(StrConv(Tstr, vbFromUnicode), Start, leng), vbUnicode))
CBMmid = CC
End Function
Public Function CBMstrLen(Wstr$) As Long
CBMstrLen = LenB(StrConv(Wstr, vbFromUnicode))
End Function
#6
忘了这个
Private Sub Form_Unload(Cancel As Integer)
vbexcel11.Quit
Set vbexcel11 = Nothing '释放内存
End Sub
Private Sub Form_Unload(Cancel As Integer)
vbexcel11.Quit
Set vbexcel11 = Nothing '释放内存
End Sub
#1
机器上有没有装excel
#2
#3
在窗体最上面工程引用 , 把它打勾即可.
#4
没装office的,只装了wps的。
谢谢Veron_04
cbm666:这个引用我找不到。555。。。。
#5
那你试这个 自定义 Excell
c:\tt.xls 改为你自己的路径与文件名
Option Explicit
Dim vbexcel11 As Object
Dim vbbook As Object
Dim Rownum%, str1$, str2$, str3$, str4$, len1%, len2%, len3%, CC$
Private Sub Form_Load()
Set vbexcel11 = CreateObject("Excel.Application") '创建excel对象
vbexcel11.Visible = True '对象可见
Set vbbook = vbexcel11.Workbooks.Open("c:\tt.xls") '打开文件
Me.Caption = "Excell 读取"
End Sub
Private Sub Command1_Click()
Me.Caption = "读取中,请稍侯...."
Rownum = 1
Me.Cls
Do Until vbexcel11.Sheets(1).Cells(Rownum, 1) = "" And vbexcel11.Sheets(1).Cells(Rownum, 2) = ""
DoEvents
str1 = vbexcel11.Sheets(1).Cells(Rownum, 1): str2 = vbexcel11.Sheets(1).Cells(Rownum, 2)
str3 = vbexcel11.Sheets(1).Cells(Rownum, 3): str4 = vbexcel11.Sheets(1).Cells(Rownum, 4)
'每个字段最长为15位,为了对齐要补空格,中文字占两位.
len1 = CBMstrLen(str1): len2 = CBMstrLen(str2): len3 = CBMstrLen(str3)
str1 = IIf(len1 > 15, CBMmid(str1, 1, 15), str1)
str2 = IIf(len2 > 15, CBMmid(str2, 1, 15), str2)
str3 = IIf(len3 > 15, CBMmid(str3, 1, 15), str3)
Print Trim(str1) & Space(15 - IIf(len1 >= 15, 15, len1)) & Trim(str2) & Space(15 - IIf(len2 >= 15, 15, len2)) & Trim(str3) & Space(15 - IIf(len3 >= 15, 15, len3)) & Trim(str4)
Rownum = Rownum + 1
Loop
Me.Caption = "Excell 读取"
MsgBox "READ OK"
End Sub
Public Function CBMmid(ByVal Tstr As String, Start As Integer, Optional leng As Variant) As String
CC = IIf(IsMissing(leng), StrConv(MidB(StrConv(Tstr, vbFromUnicode), Start), vbUnicode), StrConv(MidB(StrConv(Tstr, vbFromUnicode), Start, leng), vbUnicode))
CBMmid = CC
End Function
Public Function CBMstrLen(Wstr$) As Long
CBMstrLen = LenB(StrConv(Wstr, vbFromUnicode))
End Function
c:\tt.xls 改为你自己的路径与文件名
Option Explicit
Dim vbexcel11 As Object
Dim vbbook As Object
Dim Rownum%, str1$, str2$, str3$, str4$, len1%, len2%, len3%, CC$
Private Sub Form_Load()
Set vbexcel11 = CreateObject("Excel.Application") '创建excel对象
vbexcel11.Visible = True '对象可见
Set vbbook = vbexcel11.Workbooks.Open("c:\tt.xls") '打开文件
Me.Caption = "Excell 读取"
End Sub
Private Sub Command1_Click()
Me.Caption = "读取中,请稍侯...."
Rownum = 1
Me.Cls
Do Until vbexcel11.Sheets(1).Cells(Rownum, 1) = "" And vbexcel11.Sheets(1).Cells(Rownum, 2) = ""
DoEvents
str1 = vbexcel11.Sheets(1).Cells(Rownum, 1): str2 = vbexcel11.Sheets(1).Cells(Rownum, 2)
str3 = vbexcel11.Sheets(1).Cells(Rownum, 3): str4 = vbexcel11.Sheets(1).Cells(Rownum, 4)
'每个字段最长为15位,为了对齐要补空格,中文字占两位.
len1 = CBMstrLen(str1): len2 = CBMstrLen(str2): len3 = CBMstrLen(str3)
str1 = IIf(len1 > 15, CBMmid(str1, 1, 15), str1)
str2 = IIf(len2 > 15, CBMmid(str2, 1, 15), str2)
str3 = IIf(len3 > 15, CBMmid(str3, 1, 15), str3)
Print Trim(str1) & Space(15 - IIf(len1 >= 15, 15, len1)) & Trim(str2) & Space(15 - IIf(len2 >= 15, 15, len2)) & Trim(str3) & Space(15 - IIf(len3 >= 15, 15, len3)) & Trim(str4)
Rownum = Rownum + 1
Loop
Me.Caption = "Excell 读取"
MsgBox "READ OK"
End Sub
Public Function CBMmid(ByVal Tstr As String, Start As Integer, Optional leng As Variant) As String
CC = IIf(IsMissing(leng), StrConv(MidB(StrConv(Tstr, vbFromUnicode), Start), vbUnicode), StrConv(MidB(StrConv(Tstr, vbFromUnicode), Start, leng), vbUnicode))
CBMmid = CC
End Function
Public Function CBMstrLen(Wstr$) As Long
CBMstrLen = LenB(StrConv(Wstr, vbFromUnicode))
End Function
#6
忘了这个
Private Sub Form_Unload(Cancel As Integer)
vbexcel11.Quit
Set vbexcel11 = Nothing '释放内存
End Sub
Private Sub Form_Unload(Cancel As Integer)
vbexcel11.Quit
Set vbexcel11 = Nothing '释放内存
End Sub