Macro stopped working- No error messages

jrg24

New Member
Joined
Aug 6, 2010
Messages
49
I have a Macro that pulls a particular sheet from all workbooks in a directory and copies it into one workbook (the code is actually in the workbook, it is not in my personal workbook). It then renames these sheets based upon data from the sheet copied. I have been using this macro for several months, and it has worked fine until today. I cannot get the macro to run. I hit the run button, and nothing happens. No error messages, no nothing. I have attempted rerunning it in an existing workbook, copying an existing workbook, and copying the code and pasting into a mew module in a new workbook. All have the same result. I used this marco just yesterday with no issues. The source data location has not changed, nor has the location of the sheet containing the Macro. Any Ideas? Any help would be appreciated.

Code:
Option Explicit

Sub PullSheets()
   Dim sFolder As String
   Dim sFile As String
   Dim wbSource As Workbook
   Dim wbMaster As Workbook
   Dim ws As Worksheet
Dim strShName As String


   '====================================================
   'EDIT THIS
   sFolder = "C:\Users\Username\Documents\Annual Budget\ASPAC Submissions\"   'remember trailing backslash"
   '====================================================
   
   'set up the master workbook
   Set wbMaster = ThisWorkbook
  
   
   On Error GoTo errHandler   'reset application setting on error
   Application.ScreenUpdating = False
    Application.DisplayAlerts = False
   
   'loop through all excel files in folder
   sFile = Dir(sFolder & "*.xls*")
   Do Until sFile = ""
   
      'open the source workbook
      If sFile <> wbMaster.Name Then   'don't process the master workbook
         Set wbSource = Workbooks.Open(sFolder & sFile)
         
         'copy the first worksheet EDIT IF NECESSARY
         
         wbSource.Worksheets(9).Copy After:=wbMaster.Sheets(wbMaster.Sheets.Count)
         strShName = Mid(Range("C6").Formula, InStr(Range("C6").Formula, "[") + 1)


    strShName = Split(strShName, "-")(0) & "-" & Split(strShName, "-")(1)
    ActiveSheet.Name = strShName
         
         wbSource.Close SaveChanges:=False
         Application.CutCopyMode = False
      End If
      
      'get the next file
      sFile = Dir()
   Loop
 
    


For Each ws In Worksheets


Next
   'tidy up
   Set wbSource = Nothing
   Set wbMaster = Nothing
   
errHandler:
   Application.ScreenUpdating = True
   Application.DisplayAlerts = True
   End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Remove this line & see what happens
Code:
   On Error GoTo errHandler   'reset application setting on error
 
Upvote 0
I sent the macro code to someone else and had them run it. It worked for the other person. I am really stumped by this.
 
Upvote 0
In that case try stepping through the code line by line (using F8) to see if you can figure out where it's going wrong.
Would also be worth rebooting your machine.
 
Upvote 0
I figured out the issue. I pointed the Macro to other folders and everything worked. So, going back to my source folder, I figured out that some fo the files submitted to the folder were not in the proper file format. When I removed these files, the Macro ran as expected. I did not see it at first because the file was saved as XLSM from an XLSX file. Once I figured this out, I was able to identify that this was the cause.
 
Upvote 0
Glad you sorted it & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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