Code required

eciraje

New Member
Joined
Sep 18, 2002
Messages
49
Hello
I need to Open all the excel files in one directory. But before opening the next it shoud close the previous file .. what should i write in macro to do the step.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I havent tested this but you could use a string array to hold all the file names. You can then pass the filepaths to a sub that copies and pastes to then next unused cells in your workbook. sonething like this:

Sub yourMacro()
Dim thePath(5) as string 'number of files you have - 1

thePath(0) = "C:FileDirectoryyourFile1"
Call openWorkBook(thePath(0))

'next file
thePath(1) = "C:FileDirectoryyourFile2"
Call openWorkBook(thePath(1))

''etc until all you files are copied. you can get fancy and do this w/a loop too

End Sub

''sub to open the current workbook
Sub openWorkBook(whatPath as string)
Workbooks.Open Filename:= whatPath
'your code to copy and paste here

whatPath.Close
End Sub

This should get you started
This message was edited by DavidVee on 2002-09-25 17:03
 
Upvote 0

Forum statistics

Threads
1,214,987
Messages
6,122,613
Members
449,090
Latest member
vivek chauhan

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