Consulting

Results 1 to 5 of 5

Thread: VBA Code error from Macro Add-In

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Regular
    Joined
    Jun 2017
    Location
    Windsor Mill
    Posts
    25
    Location

    VBA Code error from Macro Add-In

    I created a Macro and tried to add it to the Excel Ribbon as a new tab and the Macro will not run properly. It keeps getting hung up at "Sheet.Copy After:=ActiveWorkbook.Sheets(1)". The Macro is to open up a bunch of files into one workbook. Below is the complete VBA code. The Macro works fine if I run it normally but not as an Add-In from the Excel Ribbon.

    Sub GetFiles()
    
    
    Path = "G:\FSG\Howard\Monthly Bank Volume Reports\Bank Report Variance File\Banks\"
    Filename = Dir(Path & "*.xls")
      Do While Filename <> ""
      Workbooks.Open Filename:=Path & Filename, ReadOnly:=True
         For Each Sheet In ActiveWorkbook.Sheets
         Sheet.Copy After:=ActiveWorkbook.Sheets(1)
      Next Sheet
         Workbooks(Filename).Close
         Filename = Dir()
      Loop
    
    
    Path = "G:\FSG\Howard\Monthly Bank Volume Reports\Bank Report Variance File\MACs\"
    Filename = Dir(Path & "*.xls")
      Do While Filename <> ""
      Workbooks.Open Filename:=Path & Filename, ReadOnly:=True
         For Each Sheet In ActiveWorkbook.Sheets
         Sheet.Copy After:=ActiveWorkbook.Sheets(1)
      Next Sheet
         Workbooks(Filename).Close
         Filename = Dir()
      Loop
      
      ChDir "G:\FSG\Howard\Monthly Bank Volume Reports\Bank Report Variance File"
        ActiveWorkbook.SaveAs Filename:= _
            "G:\FSG\Howard\Monthly Bank Volume Reports\Bank Report Variance File\Volume Summary Report.xlsm", FileFormat:= _
            xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
      End Sub
    Last edited by Bob Phillips; 06-13-2017 at 03:40 PM. Reason: Added code tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •