我想用VB从EXCEL中读取数据?

这篇博客探讨了如何使用VB从Excel文件中读取数据。作者展示了尝试读取Excel中的性别、费用和姓名数据的代码,并询问了代码是否正确。在代码中,作者检查了Excel文件是否存在,然后激活并设置了Excel应用类,读取特定单元格的数据,并执行了Excel中的宏。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我想用VB从EXCEL中读取数据?
怎么写程序?
不知道这样写对不对
Private Sub Command6_Click()
   On Error GoTo Err1
    Dim xing As String
    Dim ming As String
    Dim fei As String
   
    Dim XLApp As Excel.Application
    Dim xlBook As Excel.Workbook
    Dim xlSheet As Excel.Worksheet
   
     Text7.Text = "4582"
    Set XLApp = CreateObject("Excel.Application")
  xlSheet.Activate '激活工作表
  

  If Dir("D:/temp/excel.bz") = "" Then '判断EXCEL是否打开
    Set XLApp = CreateObject("Excel.Application") '创建EXCEL应用类
    XLApp.Visible = True '设置EXCEL可见
 
 
xing = xlSheet.Cells(1, 5)   '性别栏
  fei = xlSheet.Cells(1, 7)       '费用栏
  ming = xlSheet.Cells(1, 3)   '姓名栏

  h = xlSheet.Cells(1, 10) '卡号
Debug.Print Len(xing), xing
Debug.Print Len(ming), ming
  Debug.Print Len(fei), fei
 
  xing = hanzhuan("张佳伟")
  ming = hanzhuan(ming)
Text8.Text = "我"
        
xie(0) = xing & ming & fei & "00000000"
xie我想用VB从EXCEL中读取数据?
怎么写程序?
不知道这样写对不对
Private Sub Command6_Click()
   On Error GoTo Err1
    Dim xing As String
    Dim ming As String
    Dim fei As String
   
    Dim XLApp As Excel.Application
    Dim xlBook As Excel.Workbook
    Dim xlSheet As Excel.Worksheet
   
     Text7.Text = "4582"
    Set XLApp = CreateObject("Excel.Application")
  xlSheet.Activate '激活工作表
  

  If Dir("D:/temp/excel.bz") = "" Then '判断EXCEL是否打开
    Set XLApp = CreateObject("Excel.Application") '创建EXCEL应用类
    XLApp.Visible = True '设置EXCEL可见
 
 
xing = xlSheet.Cells(1, 5)   '性别栏
  fei = xlSheet.Cells(1, 7)       '费用栏
  ming = xlSheet.Cells(1, 3)   '姓名栏

  h = xlSheet.Cells(1, 10) '卡号
Debug.Print Len(xing), xing
Debug.Print Len(ming), ming
  Debug.Print Len(fei), fei
 
  xing = hanzhuan("张佳伟")
  ming = hanzhuan(ming)
Text8.Text = "我"
        
xie(0) = xing & ming & fei & "00000000"
xie(1) = yihuo(xie(0), 1)
xlBook.RunAutoMacros (xlAutoOpen) '运行EXCEL中的启动宏

  Else
   MsgBox ("EXCEL已打开")
  End If
Err1:
   Set XLApp = Nothing

intTime = Val(Text3.Text)
Timer1.Interval = intTime
i = 33
j = 33
Timer1.Enabled = True

End Sub
    从Set XLApp到Set XLApp = Nothing程序根本没有执行
在此区域外能执行 (在这一子程序里里边)
等待高手解决 (1) = yihuo(xie(0), 1)
xlBook.RunAutoMacros (xlAutoOpen) '运行EXCEL中的启动宏

  Else
   MsgBox ("EXCEL已打开")
  End If
Err1:
   Set XLApp = Nothing

intTime = Val(Text3.Text)
Timer1.Interval = intTime
i = 33
j = 33
Timer1.Enabled = True

End Sub
    从Set XLApp到Set XLApp = Nothing程序根本没有执行
在此区域外能执行 (在这一子程序里里边)
等待高手解决

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值