Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Macro Failed to begin Execution - ref: thread99-464072

Macro Failed to begin Execution - ref: thread99-464072

Macro Failed to begin Execution - ref: thread99-464072

Hello - I posted this issue a few years ago, without resolution.  In doing a thorough search today.  I found thread99-464072: Extra! Macro Failed to Begin Execution, this relates the issue to Arrays.  In the scripts suffering worse from this issue, there are arrays, which are not my comfort zone.  Also, in thread1-1273379: Problems with Macro execution, the same error is referenced with Global variables as the culprit.  I use Global variable in most of my macro, along with a standard set of Modules.  I am posting segments of code from a macro that runs every 15 minutes via a Shell call from task manager. Before the shell command is called, any extra processes (ebrun,ebedit,extra,ebmngr) are terminated. There doesn't appear to be an instigator for the error and it presents irregularly. I have many scripts that are prone to this error, but they run in a heavy traffic environment with a manual start, so restarting Extra is not a problem.  This macro has a dedicated PC...  

Code Sample :
'declarations specific to Array and array use
'User-Defined Type

Type IntSettings
    Ste As String
    Nm As String
    Mon As String
    Dtl As String
    NOC As String
    IVR AS String
    TmFrm As String
    Refd As String
End Type

'Helper Variables (Transaction Required)
Global Port() As IntSettings, ChkIntNm As String, ChkDesc As String, ChkStat As String, MonID As Integer, Btm As Object

Function FindInt(Ste As String, IntNm As String) As Integer
    'Tests read Interface values against Monitor list
    For Cnt = 0 To UBound(Port)
        Test = Port(Cnt).Nm
        If Ste = Port(Cnt).Ste And IntNm = Port(Cnt).Nm Then
            FindInt = Cnt
            Port(Cnt).Refd = "Y"
            Exit Function
        End If
    Next Cnt
    FindInt = 9999
End Function

Sub IntData
    'Excel Objects
    Dim appExcel As Object
    Dim wbExcel As Object
    Dim aSheet As Object
On Error GoTo ErrorHandler
    FileCopy "\\infonet\sites\CorpIT\ProvisioningOSS\ICOMS Interface Script History\ICOMs Port Monitor.xls", _
        "\\kstlmfps02\OMS\Provisioning_OSS\ITOPS-IDS\Interfaces\ICOMs Port Monitor.xls"

    Set appExcel = CreateObject("Excel.Application")
    Set wbExcel = appExcel.Workbooks.Open("\\kstlmfps02\OMS\Provisioning_OSS\ITOPS-IDS\Interfaces\ICOMs Port Monitor.xls")
    Set aSheet = wbExcel.Sheets("ICOMs")
    ReDim Port(aSheet.UsedRange.Rows.Count - 5)
    For i = 5 To aSheet.UsedRange.Rows.Count
        AID = i - 5
        Test = Trim(aSheet.Cells(i, 3).Text)
        Port(AID).Ste = Trim(aSheet.Cells(i, 2).Text)
        Port(AID).Nm = Trim(aSheet.Cells(i, 3).Text)
        Port(AID).Mon = Trim(aSheet.Cells(i, 4).Text)
        Port(AID).Dtl = Trim(aSheet.Cells(i, 5).Text)
        Port(AID).NOC = Trim(aSheet.Cells(i, 6).Text)
        Port(AID).IVR = Trim(aSheet.Cells(i, 7).Text)
        Port(AID).TmFrm = Trim(aSheet.Cells(i, 8).Text)
    Next i
End Sub

Sub Main
'Input output file setup removed
'Session configuration removed
'To the GUTS

    LastSite = "X"
'BEGIN Task execution Here

For Ste = 100 To 500 Step 100
    Site = Trim(Str(Ste))
    IntCnt = 0
    Rw = 8
    Pg = 0
        Screentest = ICOMs.GetString(1, 36, 7)
        If Screentest = "Sign On" Then    'Tests to see that Session is logged in
            If Login = "N" Then GoTo ErrorEnd
        ElseIf LastSite <> Site Then      'Tests to see that logged in Session is the correct Site
            If ChgSite = "N" Then GoTo ErrorEnd
        End If
        If FindScreen = "N" Then GoTo ErrorEnd
        If IntCnt = 0 And Pg = 0 Then TopPg1 = Trim(ICOMs.GetString(9, 6, 5))
        Set Btm = ICOMs.Search("Bottom")
        IntCnt = IntCnt + 1
        ErrRec = "N"
        ErrNOC = "N"
        ErrIVR = "N"
        ErrPortMnt = "N"
        Comment = ""
        Screentest = ""
        ChkIntNm = ""
        ChkDesc = ""
        ChkStat = ""
        MonID = 0
        Test = Rw + IntCnt - (Pg * 12)
        If Rw + IntCnt - (Pg * 12) = 21 Then
            If Btm.Top = -1 Then
                ICOMs.SendKeys ("<PF8>")
                'Screentest??? How???
                Pg = Pg + 1
                Set Btm = ICOMs.Search("Bottom")
                Exit Do  'No more records Bottom reached
            End If
        End If

        ChkIntNm = Trim(ICOMs.GetString(Rw + IntCnt - (Pg * 12), 6, 5))
        ChkDesc = Trim(ICOMs.GetString(Rw + IntCnt - (Pg * 12), 12, 20))
        ChkStat = ICOMs.GetString(Rw + IntCnt - (Pg * 12), 35, 4)
        ' Test captured data - Execute a refresh
        If ChkIntNm = "" And Btm.Top <> -1 Then Exit Do ' No More Interfaces
        If ChkStat = "****" Then
            ICOMs.SendKeys ("<PA1><PF5>")
            Screentest = Trim(ICOMs.GetString(9, 35, 1))
            If Screentest = "*" Then
                Comment = "Refresh did not clear issue"
                rc% = MsgBox(Comment, "ERROR")
            ElseIf Pg <> 0 and TopPg1 = Trim(ICOMs.GetString(9, 6, 5))Then
                For Dwn = 1 to Pg
                    ICOMs.SendKeys ("<PF8>")
                Next Dwn
            End If
            GoTo CaptrIntInfo
        ElseIf ChkStat = "" Then
            If Btm.Top <> -1 Then
                'End of list reached
                Exit Do  'No more records Bottom reached
                Comment = "Unexpected Blank Interface not at bottom"
                ErrScrape (1)
            End If
        End If
        ' Find Port in Monitor Doc
        MonID = FindInt(Site, ChkIntNm)
        If MonID = 9999 Then
            'Port Not Found
            If TmeTst = -1  And DteTst = -1 Then
                Comment = Site & "-" & ChkIntNm & "-" & ChkDesc
                ErrPortMnt = "Y"
            End If
            GoTo ErrorLog
            'Write Message to ExcNm - send to OSS - Monday - Friday 8 - 5 PM
        End If
        'Evaluate Port Monitor Triggers -
        If ChkStat = "MSGW" Or ChkStat = "NO" Then
            Comment = "Site " & Site & " " & Now() & " " & ChkIntNm & " " & ChkDesc & " is in status " & ChkStat & " check it out!!!"
            If UCase(Port(MonID).Mon) = "Y" Then ErrRec = "Y"
            If UCase(Port(MonID).NOC) = "Y" Then ErrNOC = "Y"
            If UCase(Port(MonID).IVR) = "Y" Then ErrIVR = "Y"
        End If
        'For NOC and Detail view on Select OSS/HelpDesk Ports
        If UCase(Port(MonID).Dtl) = "Y" Or UCase(Port(MonID).NOC) = "Y" Or UCase(Port(MonID).IVR) = "Y"Then
            ICOMs.MoveTo Rw + IntCnt - (Pg * 12), 2
            ICOMs.SendKeys ("7<Enter>")
            Screentest = Trim(ICOMs.GetString(1, 2, 8))
            If Screentest <> "TRFDSP" Then
                ErrScrape (1)
            End If
            'When a time frame is needed - then the search for 2 minutes ago is removed and replaced with 2 hours ago
            If Port(MonID).TmFrm = "Y" Then
                CalcTm = Time
                CalcDate = Date
                CalcHr = Hour(CalcTm)
                If CalcHr = 0 Or CalcHr = 1 Then
                     CalcHr = 24 + CalcHr
                     CalcDate = CalcDate - 1
                End If
                SrchDate = Format(CVar(CalcDate), "mmddyy")
                SrchTime = Format(CalcHr - 2, "00") & Format(CVar(CalcTm), "nnss")
                ICOMs.MoveTo 4, 2
                ICOMs.SendKeys ("<EraseEOF>" & SrchDate)
                ICOMs.MoveTo 4, 11
                ICOMs.SendKeys ("<EraseEOF>" & SrchTime)
                ICOMs.SendKeys ("<Enter>")
                Screentest = Trim(ICOMs.GetString(1, 2, 8))
                If Screentest <> "TRFDSP" Then
                    Comment = "Detail Screen not found after Time Update"
                    ErrScrape (1)
                End If
            End If
            ChkDtl = Trim(ICOMs.GetString(9, 3, 7))
            If ChkDtl = "" Then
                Comment = "Site " & Site & " " & Now() & " " & ChkIntNm & " " & ChkDesc & " is in status " & ChkStat & " and shows no transactions. Check It Out!!!"
                If UCase(Port(MonID).Mon) = "Y" Then ErrRec = "Y"
                If UCase(Port(MonID).NOC) = "Y" Then ErrNOC = "Y"
                If UCase(Port(MonID).IVR) = "Y" Then ErrIVR = "Y"
            End If            
            ICOMs.SendKeys ("<RESET>")
            ICOMs.SendKeys ("<PA1><PF3>")
            Call Sleep  
            ICOMs.SendKeys ("<PA1><PF5>")
        End If

        If Comment = "" Then Comment = "Issue Not Found"
        lastintname = ChkIntNm + " - " + Str(IntCnt) + " - " + Str(Pg) + " - " + Str(test)
        If ErrRec = "Y" Then Print #OSSHelpNo, Comment
        If ErrNOC = "Y" Then Print #NOCNo, Comment
        If ErrIVR = "Y" Then Print #IVRNo, Comment
        If ErrPortMnt = "Y" Then
            If Prt = 0 Then
                Call PortMonHdr
                Print #PortMntNo, "PORT(S) NOT FOUND IN 'ICOMs Port Monitor.xls'"
            End If          
            Print #PortMntNo, Comment  
            Prt = Prt + 1
        End If      
        LastSite = Site
Next Ste

End Site

    If FindMenu = "N" Then GoTo EndAlready
    ICOMs.MoveTo 21, 15
    ICOMs.SendKeys ("<Reset>")
    ICOMs.SendKeys ("90<Enter>") 'at any Menu:
    'Reset Session in case Logoff failed
    Sess0.Connected = False
    pause (2)
    PrtStrt = Prt
    If TmeTst = -1  And DteTst = -1 Then  '
        For Cnt = 0 To UBound(Port)
            If Port(Cnt).Refd <> "Y" Then
                If Prt = 0 Then
                    Call PortMonHdr
                    Print #PortMntNo, "PORT(S) FROM 'ICOMs Port Monitor.xls' NOT FOUND IN BILLING"              
                Elseif PrtStrt = Prt Then
                    Print #PortMntNo, "PORT(S) FROM 'ICOMs Port Monitor.xls' NOT FOUND IN BILLING"
                End If                     
                Comment = Port(Cnt).Ste & "-" & Port(Cnt).Nm & "-NOT FOUND"
                Print #PortMntNo, Comment
                Prt = Prt + 1
            End If
        Next Cnt
    End If
End Sub

RE: Macro Failed to begin Execution - ref: thread99-464072

Thanks for looking at my issue.  I clipped quite a lot out of the code I posted including the session disconnect and close commands.

Thanks Again

RE: Macro Failed to begin Execution - ref: thread99-464072

Is there a reason you're using global variables?  Do you have other macros that share that information?  If not, you might simply Dim those variables instead.

It looks like you never explicitly close Excel.  It's probably not related, but you might want to close it when you're finished.

RE: Macro Failed to begin Execution - ref: thread99-464072

Okay, I fixed the issue! It was really stupid.  Until recently I have started all macros from the editor. I use the editor specifically for the stop button if there is an issue. SO starting a script via command line is a newer process for me.  Starting from the Editor, a macro won't run unless it compiles correctly, but it will still give the Failed Execution error in some circumstances, which an Attachmate restart ALWAYS resolves.  When I read the posts recommendations to compile for errors, I was disappointed, because that was already done!! SOOOOOO now that I have a script running via the task manager, I understand why the responses always said COMPILE.  A syntax error, that would stop you in the editor when running via EBrun will generate a "Macro Failed to begin execution".  So a typo caused 6 HOURS of troubleshooting.

Your Questions:
Within the complete version of this macro there are 10 modules that the Main references. 9 of the modules are not unique to this macro, all scripts for this billing system also have those modules. In the past, my team worked with having all variables dimmed locally, but when we made changes to a module or went to use that updated versionin another script, finding all the references became very tedious. We don't have multi macros running simultaneously on a single PC; Instead we moved to a server and connect with Remote Desktop.  This allows multiple sessions, but the sessions can't seee the other variables.

If you would like to see the complete code I would be happy to e-mail it??  When I posted the code, I was thinking the issue was with the array.  So my code clipping targetted where the arrays was declared, loaded, and used. I didn't include many of the cleanup steps.

I appreciate your feedback on this, and also your responses on MANY other threads.  Tektips is my first resource (after HELP) when I am stumped with troubleshooting. Thanks

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close