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

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

DavidVee

New Member
Joined
Sep 22, 2002
Messages
28
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
 
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,164,668
Messages
5,838,680
Members
430,563
Latest member
Raeyven

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