Activate a Worksheet
Hey Sean,
Did you try :
Workbooks(excelFilename).Sheets(wsName).Range( ) ... ??
You could also try the following:
Public Function FindWorksheet(wsName as String) as Worksheet
Dim aWS as Worksheet
For Each aWS in ActiveWorkbook
If aWS.Name = wsName then
Set FindWorksheet = aWS
Exit Function
End If
Next aWS
Set FindWorksheet = Nothing
End Function
You'd call this function like this :
Dim myWorksheet as Worksheet
.... ' (some code)
Set myWorksheet = FindWorksheet(wsName)
myWorksheet.Range().Select ... ' whatever you want to do ...
Hope this helps,
Chad
"Sandy" wrote:
Replace Sheets(wsName).Select
with WorkSheets(wsName).Select
Sandy
Sean wrote:
For some reason, when I open up a workbook with several worksheets, I
am not able to activate a worksheet to select a range. Here's the
code:
Workbooks(excelFilename).Activate
Sheets(wsName).Select
Both excelFilename and wsname are Dim as String. As I trace the code,
it opens the workbook, but it will not select the sheet wsName.
For example, it will open the workbook and Sheet1 is active. When it
hits the Sheets(wsName).Select part of the code (where wsName is
"Sheet3), it does not switch to Sheet3.
I've also tried Sheets(wsName).Activate, and this does not work either.
|