通过Command Dialog控件选择后如果相应行有数据则不能修改,如果没有数据则可以修改。
如修改第一行第一列为abc。
Dim CW_FileName As String
Dim CW_FileTitle As String
Dim CW_APP As Excel.Application
Dim CW_BOOK As Excel.Workbook
Dim CW_Sheet As Excel.Worksheet
Dim CW_Templatefile As Excel.Workbook
Dim CW_Objectfile As Excel.Workbook
Private Sub CommandButton2_Click()
CommonDialog1.Filter = "Excel file (*.xls)|*.xls"
CommonDialog1.ShowOpen
CW_FileTitle = CommonDialog1.FileTitle
CW_FileName = CommonDialog1.Filename
Set CW_APP = CreateObject("Excel.Application")
Set CW_BOOK = CW_APP.Workbooks.Open(CW_FileName)
Set CW_Sheet = CW_BOOK.Worksheets(1)
CW_Sheet.Activate
CW_Sheet.Cells(1, 1) = "abc"
CW_APP.DisplayAlerts = False
CW_APP.Quit
End Sub