当前位置:编程学习 > VB >>

VB操作excle提示用户定义类型未定义

我在网上找了一段VB操作Excle的代码
Private   Sub   Command1_Click() 
        '引用   Microsoft   Excel   11.0   Object   Library 
        Dim   xlsApp   As   Excel.Application 
        Dim   eworkbook   As   Workbook 
        Dim   eworksheet   As   Worksheet 
        
        Set   xlsApp   =   New   Excel.Application 
        Set   eworkbook   =   xlsApp.Workbooks.Open( "D:\sp.xls ") 
        Set   eworksheet   =   eworkbook.Sheets( "Sheet1 ") 
        
        With   eworksheet 
                '1 
                .Cells(1,   1)   =   "1 " 
                .Cells(1,   2)   =   "2 " 
                .Cells(1,   3)   =   "3 " 
                '2 
                .Cells(2,   1)   =   "11 " 
                .Cells(2,   2)   =   "22 " 
                .Cells(2,   3)   =   "33 " 
                '3 
                .Cells(3,   1)   =   "111 " 
                .Cells(3,   2)   =   "222 " 
                .Cells(3,   3)   =   "333 " 
        End   With 
        
        eworkbook.Save 
        eworkbook.Close 
        xlsApp.Quit 
End   Sub
但是我一点运行就提示 用户定义类型未定义,请问各位大侠,怎么办啊。。。 --------------------编程问答-------------------- 你有没有引用EXCEL呀 --------------------编程问答-------------------- 跪求如何引用,越详细越好>_<。。。。 --------------------编程问答-------------------- 菜单 “工程”-》“引用”
找到 Microsoft Excel 11.0 Object Library   --------------------编程问答--------------------
Private Sub Command1_Click()
    '引用 Microsoft Excel 11.0 Object Library
    Dim xlapp As Variant
    Dim xlsApp As Variant ' Excel.Application
    Dim eworkbook As Variant
    Dim eworksheet As Variant
    Set xlsApp = CreateObject("excel.application")
    Set eworkbook = xlsApp.Workbooks.Open("D:\sp.xls")
    Set eworksheet = eworkbook.Sheets("Sheet1")
    With eworksheet
        '1
        .Cells(1, 1) = "1 "
        .Cells(1, 2) = "2 "
        .Cells(1, 3) = "3 "
        '2
        .Cells(2, 1) = "11 "
        .Cells(2, 2) = "22 "
        .Cells(2, 3) = "33 "
        '3
        .Cells(3, 1) = "111 "
        .Cells(3, 2) = "222 "
        .Cells(3, 3) = "333 "
    End With
    eworkbook.Save
    eworkbook.Close
    xlsApp.Quit
End Sub
--------------------编程问答-------------------- 谢谢大侠
补充:VB ,  基础类
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,