Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try Dim excelObj As Object = GetObject(, "Excel.Application") If excelObj.Workbooks.Count = 0 Then '注意,如果是新建未保存的工作簿不算打开 MsgBox("没有工作簿打开") excelObj = Nothing Exit Sub End If excelObj.Workbooks(1).Worksheets(1).Range("A1").Value = "222" '表示把已经打开的第一个工作簿的第一个工作表的A1单元格赋值为“222” excelObj = Nothing Catch ex As Exception MsgBox(ex.Message) End Try End Sub (责任编辑:huang) |