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.
 

Some videos you may like

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,477
Messages
5,596,384
Members
414,063
Latest member
N_Bates

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