我想将excelsheet1的列A的值获取到Visual Basic的某个变量中,然后在更改该值后发送回下一个sheet2
这是一个完整且有效的项目示例,它将值从 Sheet1、单元格 A1 复制到 Sheet2、单元格 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)