ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Run Macro on multiple files (https://www.excelbanter.com/excel-discussion-misc-queries/201474-run-macro-multiple-files.html)

LoriH

Run Macro on multiple files
 
I have an excel macro that I created to format a spreadsheet a certain way.
I want to run this macro on all the files in a specified folder. I am new to
macros and VBA. What is the easiest way to do this?

Thanks in advance!

Gary''s Student

Run Macro on multiple files
 
The following macro goes to the specified folder and lists the excel files in
that folder in column A.

The macro then goes down the list, opens each file, runs macroxx, and then
saves and closes the file:


Sub list_um()
Dim F As String
Dim roww As Long
roww = 0
Dim FileLocSpec As String
FileLocSpec = "C:\Temp\*.xls"
F = Dir(FileLocSpec)
Do Until F = ""
roww = roww + 1
Cells(roww, 1).Value = F
F = Dir
Loop

Set r = Range("A1")
While r.Value < ""
Workbooks.Open Filename:="C:\Temp\" & r.Value
Call macroxx
ActiveWorkbook.Save
ActiveWorkbook.Close
Set r = r.Offset(1, 0)
Wend
End Sub

--
Gary''s Student - gsnu200802


"LoriH" wrote:

I have an excel macro that I created to format a spreadsheet a certain way.
I want to run this macro on all the files in a specified folder. I am new to
macros and VBA. What is the easiest way to do this?

Thanks in advance!


LoriH

Run Macro on multiple files
 
This worked great. I was getting an error message at first but added a
msgbox to tell me when the files were all formatted and it went away. Thansk!

"LoriH" wrote:

I have an excel macro that I created to format a spreadsheet a certain way.
I want to run this macro on all the files in a specified folder. I am new to
macros and VBA. What is the easiest way to do this?

Thanks in advance!


TFMR

Run Macro on multiple files
 
Hi LoriH,

Kindly help me, where I have to write this macro? I have same issue please
help me to write this macro.

Thanks

"LoriH" wrote:

This worked great. I was getting an error message at first but added a
msgbox to tell me when the files were all formatted and it went away. Thansk!

"LoriH" wrote:

I have an excel macro that I created to format a spreadsheet a certain way.
I want to run this macro on all the files in a specified folder. I am new to
macros and VBA. What is the easiest way to do this?

Thanks in advance!


TFMR

Run Macro on multiple files
 
Hi Gary'' Student,

Your macro help me, but there is one more query that I have files in CSV and
when I run macro so all the times asking to save it Press Yes NO Cancel.

I want that all the files saves automaticall, without pressing YES for all
reports one by One.

Thanks

"Gary''s Student" wrote:

The following macro goes to the specified folder and lists the excel files in
that folder in column A.

The macro then goes down the list, opens each file, runs macroxx, and then
saves and closes the file:


Sub list_um()
Dim F As String
Dim roww As Long
roww = 0
Dim FileLocSpec As String
FileLocSpec = "C:\Temp\*.xls"
F = Dir(FileLocSpec)
Do Until F = ""
roww = roww + 1
Cells(roww, 1).Value = F
F = Dir
Loop

Set r = Range("A1")
While r.Value < ""
Workbooks.Open Filename:="C:\Temp\" & r.Value
Call macroxx
ActiveWorkbook.Save
ActiveWorkbook.Close
Set r = r.Offset(1, 0)
Wend
End Sub

--
Gary''s Student - gsnu200802


"LoriH" wrote:

I have an excel macro that I created to format a spreadsheet a certain way.
I want to run this macro on all the files in a specified folder. I am new to
macros and VBA. What is the easiest way to do this?

Thanks in advance!



All times are GMT +1. The time now is 10:02 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com