View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Susan Susan is offline
external usenet poster
 
Posts: 1,117
Default variable sheet names not working

this is from a userform code connected to one workbook. the code then
opens a 2nd workbook & selects a certain sheet based on what month it
is. then i have to switch back & forth between the 2 workbooks..... i
can qualify the sheet i need in the workbook that the userform is in,
but for some reason it won't let me qualify the sheet in the OTHER
workbook, even tho i've identified the workbook, etc.
any ideas?
xxxxxxxxxxxxxxxxxxxxx
Sub cmdExport_click()

Me.Hide

myFileName = ThisWorkbook.Name
myPath = ThisWorkbook.Path

mySheet = Workbooks(myFileName).ActiveSheet.Name 'this works fine

Workbooks.Open Filename:="\\Server\users\Susan\My
Documents\Miscellaneous\Excel Help\Macro Projects-Excel\RPC Book1.xls"

myRPC = ActiveWorkbook.Name 'this works fine

'open the correct worksheet by month
Call MonthNumber
Call Select_Sheet

myRPCSheet = Workbooks(myRPC).ActiveSheet.Name '****this is where it
bombs....

'switch back to the invoice workbook
Workbooks(myFileName).Activate

end sub
xxxxxxxxxxxxxxxxx

i hate to use "activeworkbook" to qualify that 2nd sheet, even though
the correct one IS active at that point; i wanted to use the actual
workbook name.
the error i get is "run-time error 91 - object variable or with block
variable not set".
thanks for any help.
susan