加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

vb6 – 在Visual Basic 6中编写Excel工作表

发布时间:2020-12-17 00:03:20 所属栏目:大数据 来源:网络整理
导读:我想获得excel sheet1的A列值到visual basic的某个变量,然后在更改此值后再发送回下一个sheet2 这是一个完整且有效的项目示例,它将Sheet1,Cell A1中的值复制到Sheet2,Cell A1: ' declare these variables you need to add a reference' to the microsoft ex
我想获得excel sheet1的A列值到visual basic的某个变量,然后在更改此值后再发送回下一个sheet2
这是一个完整且有效的项目示例,它将Sheet1,Cell A1中的值复制到Sheet2,Cell A1:
' declare these variables & you need to add a reference
' to the microsoft excel 'xx' object library.

' you need two command buttons: cmdCopy and cmdSave
' on the form,an excel file in c:book1.xls

Dim xl As New Excel.Application
Dim xlsheet As Excel.Worksheet
Dim xlwbook As Excel.Workbook

Private Sub cmdCopy_Click()

    Dim temp As String

    temp = xlsheet.Cells(1,1) ' row 1 col 1

    ' TODO: process the value stored in the variable 'temp'
    temp = temp & "-changed"    ' in this case "<Sheet1-CellA1-value>-changed"

    ' Open Sheet2
    Set xlsheet = xlwbook.Sheets.Item(2)
    ' write the value to cell A1 on Sheet2
    xlsheet.Cells(1,1) = temp

End Sub

Private Sub cmdSave_Click()
    xlwbook.Save
    ' You MUST do this or you will not be able to open
    ' c:book1.xls again,untill you restart Windows OR
    ' kill EXCEL.EXE with the Task Manager
    xl.ActiveWorkbook.Close False,"c:book1.xls"
    xl.Quit
End Sub

Private Sub Form_Load()
    Set xlwbook = xl.Workbooks.Open("c:book1.xls")
    Set xlsheet = xlwbook.Sheets.Item(1)
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set xlwbook = Nothing
    Set xl = Nothing
End Sub

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读