Multiple Files: Activate problem

bhanu2003

Board Regular
Joined
Dec 9, 2003
Messages
76
Hi,

I have a set of files in a folder that i open for processing, also at the same time for each workbook opened from the folder, i need to write into another workbook, save and then cotinue processing the book i had opened from the folder. I have been able to it until writing it into the new workbook, but when i try to activate the one opened initially, i get an error msg "Subscript out of range", Run-time error - 9, am familiar with this error, but am not sure why it is showing up now.

code just before error:

Activeworkbook.save
Workbooks(sheetName).activate

SheetName has been passed from another module, also declared asa public.

Thanks in advance,
Bhanu
:rolleyes:
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

bhanu2003

Board Regular
Joined
Dec 9, 2003
Messages
76
Hi,

Just replying to see if any body reminds me of what is wrong here.

Thanks,
Bhanu
 

Cbrine

Well-known Member
Joined
Dec 2, 2003
Messages
3,196
Have you tried setting up references when the workbook is opened?

Dim Wb as workbook, Ws as worksheet
Dim PB as workbook, ps as worksheet

Set Wb = Activeworkbook
Set ws = activesheet

Workbooks.open "FileName"

Set pb = Activeworkbook
Set ps = Activesheet

When you are ready to switchback to the orginal WB just WB.activate and you know the reference is the correct reference. You also get the advantage of getting a drop down listing of functions when you type wb. or ws.
 

bhanu2003

Board Regular
Joined
Dec 9, 2003
Messages
76
The references look fine to me, also, wont this code work,

Fsheet = Activeworkbook.name

[ Process data, open and write another book]
[ save the second book]

workbooks(Fsheet).activate

i have this and doesnot seem to work, any ideas.

Thanks,
Bhanu
:cry:
 

Cbrine

Well-known Member
Joined
Dec 2, 2003
Messages
3,196
They look right, but I know in the past, I had problems caused by activesheet not pointing to what you think it might be pointing to. I usually happens when switching back and forth between sheets. I don't know if this is your issue or not, but it might be something to confirm.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,096
Messages
5,768,058
Members
425,451
Latest member
JohnBrooksBiddle

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top