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

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
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.
 
Upvote 0
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:
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,071
Latest member
cdnMech

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
Back
Top