Avatar of angel7170
angel7170
Flag for United States of America asked on

Excel 2013 macro run on multiple files

Hello,

I have a folder that contains multiple CSV files and I have 2 macros in a excel file that needs to be run.

First, I want to run those 2 macros on all the CSV files and then save it as Excel file. I am trying a VBscript from below but it is throwing an error that it could not find the macro excel file.

Please assist

Option Explicit

    LaunchMacro

    Sub LaunchMacro()
      Dim xl
      Dim xlBook      

        Set xl = CreateObject("Excel.application")
        Set xlBook = xl.Workbooks.Open("C:\TEST\CASE_FILING_BASIS_23-MAR-16", 0, False)      
        xl.Application.Visible = True
        xl.Application.run "Highlight_Results_Macro"
        xl.DisplayAlerts = False        
        xlBook.saved = True
        xl.activewindow.close
        xl.Quit

        Set xlBook = Nothing
        Set xl = Nothing

End Sub
VB ScriptMicrosoft Excel

Avatar of undefined
Last Comment
Frank Helk

8/22/2022 - Mon
Jake Lohse

You must specify the file extension as well (Probably.xlsm).  Try it like this:

 Set xlBook = xl.Workbooks.Open("C:\TEST\CASE_FILING_BASIS_23-MAR-16.xlsm", 0, False) 

Open in new window

angel7170

ASKER
Oh I see the problem here.
Actually that file is one of the CSV file. It doesn't have the macros in it. I want this CSV file to get the macros from this spreadsheet "Highlight_Results_Macro" , run and save as xls file. I am trying it for one file but there will be more than one CSV file in that folder and I want the macros to be run on all of them.
Jake Lohse

So for the one file, you should be opening it with this line:

Set xlBook = xl.Workbooks.Open("C:\TEST\CASE_FILING_BASIS_23-MAR-16.csv", 0, False)

Open in new window


Where is the "Highlight_Results_Macro" saved?  Is it in an add-in or your personal.xlsb workbook?  Perhaps it is in a workbook that should already be open?  We just need to do a better job of pointing to the macro.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
angel7170

ASKER
It is in the same folder. Name of the macro is "FormatResult"
ASKER CERTIFIED SOLUTION
byundt

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Jerry Paladino

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
byundt

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
angel7170

ASKER
Thank you
Frank Helk

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.