View Single Post
  #1   Report Post  
Randy
 
Posts: n/a
Default Use Sheet CodeNames to Select Sheet in Different Workbook

I'm using an .xla to make modifications to another workbook. In my
procedure, I'm need to test the name of each worksheet to determine how
to proceed. For some reason, I am unable to correctly point to capture
the sheet name in the other workbook. I have tried a few different
methods, none with any success.

Here is the abbreviated code:

Sub UnprotectSheets(strUpdateWb As String)
'where strUpdateWb is the name of an open workbook

Windows(strUpdateWb).Activate
Dim wb As Workbook
Set wb = ActiveWorkbook

'Attempt #1
Dim temp As String
temp = wb.Sheet1.Name
MsgBox (temp) 'yields a run-time error. code stops.

'Attempt #2
temp = Sheet1.Name
MsgBox (temp) 'gives me the sheet name from the xla. I need the
sheet name from the xls workbook

'Attempt #3
temp = strUpdateWb.Sheet1.Name
MsgBox (temp) 'run time error again

End Sub

Can anybody point me in the right direction?

Thanks,
Randy Eastland