Looping through all files in a directory, but open file does not loop

shelim481

New Member
Joined
Aug 30, 2018
Messages
28
Please help, my issue is that the code below works but not for active work book, so when i run the macro from the a open workbook in the same directory, it works for all the files but not for the one thats opened and im running from...

i want it to run for the file thats open too.


Code:
Allfolders = MsgBox("Do you want to Run for All files in this folder", vbYesNo)
    If Allfolders = vbYes Then
	
    If Right(MyPath, 1) <> Application.PathSeparator Then MyPath = MyPath & Application.PathSeparator
    Fname = Dir(MyPath & "*.xlsm")


    'loop through the files
    Do While Len(Fname)


        With Workbooks.Open(MyPath & Fname)
        
           ' code here
End With
            xFileName = Dir
        Loop
    End If
 
Try copying what is between these two lines
Code:
With Workbooks.Open(MyPath & Fname)
        
           
End With
& pasting it after the loop
 
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Can you post the entire code
 
Upvote 0

Forum statistics

Threads
1,214,922
Messages
6,122,281
Members
449,075
Latest member
staticfluids

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