Setting a variable = ActiveWorkbook
Thanks Jim. When I run your code, I do get message boxes with all the sheet
names in the active workbook. However, when I try to set ws1 and ws2, I still
get the same error. I've checked the sheet names, and they're spelled
correctly with no spaces. Any other thoughts?
"Jim Thomlinson" wrote:
Just to clarify, no this is not necessarily simple. The fact that you are new
to VBA and you are setting workbook objects is impressive in and of itself...
On to your question. Your code looks good by me. Are you sure that you have a
sheet called
"Individuals". Check for blank spaces in the actual worksheet name since
"Individuals " is different from
"Individuals"
Beyond that try
Dim myWbk as Workbook
dim wks as worksheet
Dim ws1 as Worksheet
Dim ws2 as Worksheet
Set myWkb = ActiveWorkbook
for each wks in myWkb.worksheets
msgbox wks.name
next wks
--
HTH...
Jim Thomlinson
"Cheryl" wrote:
I know this should be simple, but I'm pretty new to VBA and can't seem to get
it to work. My code:
Dim myWbk as Workbook
Dim ws1 as Worksheet
Dim ws2 as Worksheet
Set myWkb = ActiveWorkbook
It never sets the value of the variable, so when I try:
Set ws1 = myWbk.Worksheets("Individuals")
I get "Run Time Error 91 - Object variable or With block variable not set"
What in the world am I doing wrong?
Thanks,
Cheryl
|