【求大神教小白】关于vb打开excel并计算保存的问题
本人VB新手,现在想编写一个程序,大致想做到以下效果:1.打开一个excel在commondialog中
2.对已打开在commondialog的excel进行第一列计算,并将结果输出到第二列并保存
现小弟大致写了下语句,但是错误很多,而且也不知道怎么改(本人真心是小白,所以特来论坛求教!)
Private Sub Command1_Click()
On Error GoTo ErrHandler
CommonDialog1.Filter = "Microsoft office Excel 文件(*.xls)|*.xls"
CommonDialog1.FilterIndex = 1
CommonDialog1.ShowOpen
Exit Sub
ErrHandler:
End Sub
Private Sub Command2_Click()
Dim xlsApp As Excel.Application
Dim xlsBook As Excel.Workbook
Dim xlsSheet As Excel.Worksheet
Set xlsApp = CreateObject("Excel.Application")
Set xlsBook = Workbooks.Open(CommonDialog1)
xlsBook.Visible = False
Set xlsSheet = xlsBook.Worksheets("Sheet1")
Dim N
For N = 1 To Application.CountA(ActiveSheet.Range("A:A"))
Cells(N, 2) = Cells(N, 1) * Cells(N, 1) + 10
xlsBook.Save
Next
xlsBook.Close
End Sub
真心求助群里各位大神求教!拜托拜托