更新时间:2023-11-25 15:41:52
这样的事情应该可以胜任;)
Something like that should do the job ;)
Private Sub btnMinSummaryWorksheet_Click(sender As Object, e As EventArgs) Handles btnMinSummaryWorksheet.Click
'This procedure runs when the btnOpenSummaryWorksheet button is clicked. Calls the
'Sub procedure opens the Summary Worksheet Dashboard
Dim xlApp As Excel.Application
Try
'get an existing excel.application object
xlApp = CType(GetObject(, "Excel.Application"), Application)
Catch ex As Exception
'no existing excel.application object - create a new one
xlApp = New Excel.Application
End Try
Dim xlBook As Excel.Workbook
Dim xlWBName As String = "2011.1004.Compensation Template"
xlApp.Visible = True
Try
'get the opened workbook
xlBook = xlApp.Workbooks(xlWBName & ".xlsx")
Catch ex As Exception
'open it
xlBook = xlApp.Workbooks.Open("F:\Test Environment\Compensation Workbook\Compensation Workbook\bin\Debug\" & xlWBName & ".xlsx")
End Try
Dim xlSheet As Excel.Worksheet
xlSheet = CType(xlBook.Sheets("SummaryWorksheet"), Worksheet)
xlSheet.Activate()
End Sub
另一种方法是遍历工作簿集合;)
Another way is to iterate through the collection of Workbooks ;)