VBA Not Working

AllDay

New Member
Joined
Jul 28, 2016
Messages
12
My goal here is to open files in a separate folder, run the macro in each file, close and save it. The macro in that workbook updates 15 power queries.

The Code Completes The Loop and opens all files, changes the value in A1 and saves them. It however is not running the macro from the other work book to update those power queries. (The macro in that workbook when run in that book does update the power queries though). It is executed by clicking a button and don't know if that is causing the hangup. Any help is greatly appreciated.

Code:
Sub AllFiles()
Dim folderPath as String
Dim filename As String

folderPath = "My File Path"

If Right (folderPath, 1) <>"\" Then folderPath = folderPath + "\"

filename = Dir (folderPath & "*.xlsm")
Do While filename <> ""
Application.ScreenUpdating = False
Set wb = Workbooks.Open(folderPath & filename)
ActiveWorkbook.Sheets("My Sheet Name").Activate
Range("A1").Value = "My Value"

Call MyMacro

filename = Dir

ActiveWorkbook.Close SaveChanges:=True

Loop

Application.ScreenUpdating = True

MsgBox "Completed"

End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
If your MyMacro is in a standard module, try
Code:
Application.Run ("'" & wb.Name & "'!MyMacro")
Instead of
Code:
Call MyMacro
 
Upvote 0
I have 200 sequentially named files. I am assuming wb.Name is wb."Name of each workbook in folder"? What would be best way to tackle that?
 
Upvote 0
As each file is opened, the Mymacro in that file will run
 
Upvote 0
Awesome that got it done. Now as I stated this updates 15 Power Queries. Is there a way create an error log if one of the queries doesn't update?
 
Upvote 0
Is there a way create an error log if one of the queries doesn't update?
I have never used power queries, so unfortunately, cannot help on that.
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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