macro to open a series of excel files

p4nny

Board Regular
Joined
Jan 13, 2015
Messages
246
Hi,

I would like a macro:


- to open an excel file in a specified location
- delete the first 6 rows
- save
- and close

next workbook (same as above) until completed


appreciate the guidance

anthony
 
Hi!
You can use this. I tested it out and it worked nicely.

Code:
Sub DeleteRowsMultipleWorkBooks()


Dim directory As String, filename As String
'Directory, where all your needed workbooks are
directory = "C:\Users\Username\Documents\My_examplefolder\"

filename = Dir(directory & "*.xl??")
'Do-loop trough all files stored in directory
Do While filename <> ""
Workbooks.Open (directory & filename)
With Workbooks(filename)
Sheets(1).Rows("1:6").Delete
.Save
.Close
End With
filename = Dir()
Loop
End Sub

Remember, this will delete first 6 rows from all your workbooks stored in that folder.
Create blank workbook for this one and don't store it in the same folder, just in case. I'm not sure it'll work if its in the same folder.


Hope this works for you,
Matias
 
Upvote 0

Forum statistics

Threads
1,226,835
Messages
6,193,230
Members
453,781
Latest member
Buzby

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