Can someone help me fix the following code that seems to work fine with respect to activating the desired Excel worksheet called "TEST_Agg.xls". I get a "method" error message on the line: Sheets("Agg"
.select
What I really do not understand is that the variable integer "NumWkBs" is "zero" even though the "For each WkBk" statement sorts thru my open workbooks? I assume that is what is causing my problem.
As always, thanks much for any help.
Dim xlApp As Excel.Application
Dim WkBk As Excel.Workbook
Dim WkSheet As Excel.Worksheet
Dim NumWkBks As Integer
Dim xName As String
Set xlApp = GetObject(, "Excel.Application"
' xlApp.Visible = True
NumWkBks = Workbooks.Count
'Following finds an open WkBk named "TEST_Agg.xls"
For Each WkBk In xlApp.Workbooks
xName = WkBk.Name
If xName = "TEST_Agg.xls" Then
WkBk.Activate
Set WkSheet = WkBk.Sheets("Agg"
Exit For
End If
Next WkBk
NumWkBks = Workbooks.Count
Sheets("Agg"
.Select
Range("D8"
.Select
What I really do not understand is that the variable integer "NumWkBs" is "zero" even though the "For each WkBk" statement sorts thru my open workbooks? I assume that is what is causing my problem.
As always, thanks much for any help.
Dim xlApp As Excel.Application
Dim WkBk As Excel.Workbook
Dim WkSheet As Excel.Worksheet
Dim NumWkBks As Integer
Dim xName As String
Set xlApp = GetObject(, "Excel.Application"
' xlApp.Visible = True
NumWkBks = Workbooks.Count
'Following finds an open WkBk named "TEST_Agg.xls"
For Each WkBk In xlApp.Workbooks
xName = WkBk.Name
If xName = "TEST_Agg.xls" Then
WkBk.Activate
Set WkSheet = WkBk.Sheets("Agg"
Exit For
End If
Next WkBk
NumWkBks = Workbooks.Count
Sheets("Agg"
Range("D8"