Results 1 to 5 of 5

After renaming module, macros can no longer be called using application.run

Threaded View

  1. #1
    Registered User
    Join Date
    03-23-2012
    Location
    Boston, MA
    MS-Off Ver
    Excel 2010
    Posts
    7

    After renaming module, macros can no longer be called using application.run

    Thanks in advance! We are banging our heads on the wall with this one...

    We have built a report automation system.

    The system resides in a "master" workbook called report inventory. We have a list of file names in the "report inventory" that the system loads into an array. It then loops through the array opening each report, and calls a "main" update macro that resides within each report.

    The system was working fine until we renamed the module containing the "main" update macro (the one within each report). We have compiled the code, and we have tried renaming the module with a sub routine from within the project, but nothing is working. It breaks at this line in the code (full code included at the bottom):

    Application.Run "'" & activereport & "'!main"
    Note:
    • Macros are not disabled in any of the workbooks
    • All procedures are public
    • The syntax is correct (remember it runs before we rename the module)


    The error we are getting is #1004 with a description of:
    "Cannot run the macro ''NEJM Test Report 4.xlsm'!main'. The macro may not be available in this workbook or all macros may be disabled."
    Here's our code:

    Option Base 1   'Start index numbers for array at 1
    
    Sub reportUpdateSystem()
    
    Dim ReportsToBeUpdated() As String
    Dim my_range As Range
    Dim activereport As String
    Dim vArray As Variant
    Dim sArray() As String
    Dim i As Long
    
    Application.DisplayAlerts = False
    
    Set my_range = Range("B7:B8")
    
    vArray = my_range.Value
    ReDim sArray(1 To UBound(vArray))
    
    For i = 1 To UBound(vArray)
        sArray(i) = vArray(i, 1)
    Next
    
    For i = 1 To UBound(sArray)
    
    On Error GoTo ErrorHandler
        
        activereport = sArray(i)
        Application.Workbooks.Open Filename:="C:\TestReports\" & activereport
    'ERROR OCCURS ON NEXT LINE:
        Application.Run "'" & activereport & "'!main"
        Workbooks(activereport).Close True
       
    Next
    
    Exit Sub
    
    ErrorHandler:
    
    Dim Problem As String
    Dim currentReportname As String
    
    Problem = Err.Description & vbLf & vbLf & "Error number: " & Err.Number & vbLf & vbLf & "Uh oh! Something went wrong"
    currentReportname = ActiveWorkbook.Name
    
    Call errorAlerts(Problem, currentReportname)
    
    Resume Next
    
    End Sub
    Last edited by tblasko; 03-08-2013 at 12:31 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1