Solved

Run-time error '5' Excel VBA Script

Posted on 2014-04-17
3
501 Views
Last Modified: 2014-05-03
I have written a script to go through vulns and determine the application the vuln applies to. But i get a run-time errors and not sure why. Here is the code.
Sub Format()
    
    screenUpdateState = Application.ScreenUpdating
    statusBarState = Application.DisplayStatusBar
    calcState = Application.Calculation
    eventsState = Application.EnableEvents
    displayPageBreakState = ActiveSheet.DisplayPageBreaks
    
    Application.ScreenUpdating = False
    Application.DisplayStatusBar = False
    Application.Calculation = xlCalculationManual
    Application.EnableEvents = False
    displayPageBreakState = ActiveSheet.DisplayPageBreaks
    
    Dim re As New RegExp
    
    re.Pattern = "MS[0-9][0-9]-[0-9][0-9][0-9]"
    re.IgnoreCase = True
    re.Global = True
    
    Sheetcount = ThisWorkbook.Worksheets.Count
    For N = 1 To Sheetcount
    'For N = 1 To 1
        Sheets(N).Select
        
        ActiveSheet.DisplayPageBreaks = False
        
        Worksheets(N).Range("H1").Value = "Vulnerability Type"
        Columns("H:H").EntireColumn.AutoFit
        Worksheets(N).Range("I1").Value = "Microsoft Severity"
        Columns("I:I").EntireColumn.AutoFit
        'Worksheets(N).Range("J1").Value = "CVE Severity"
        'Columns("J:J").EntireColumn.AutoFit
        numrows = Worksheets(N).UsedRange.Rows.Count
        'For C = 2 To numrows
        For C = 1590 To numrows
            If InStr(Range("D" & C).Value, "jre-") Then
                Range("H" & C).Value = "Java"
            ElseIf InStr(Range("D" & C).Value, "adobe-") Then
                Range("H" & C).Value = "Adobe"
            ElseIf InStr(Range("D" & C).Value, "oracle-") Then
                Range("H" & C).Value = "Oracle"
            ElseIf InStr(Range("D" & C).Value, "mfsa") Then
                Range("H" & C).Value = "Mozilla"
            ElseIf InStr(Range("D" & C).Value, "windows-") Then
                Range("H" & C).Value = "Windows"
            ElseIf Range("D" & C).Value = "" Then
                Range("H" & C).Value = ""
            Else
                Range("H" & C).Value = "Other"
            End If
            Set allMatches = re.Execute(Range("D" & C).Value)
            If allMatches.Count > 0 Then
                tempString = getMsSeverity(Left((Range("G" & C).Value), 8))
                If InStr(tempString, "Critical") Or InStr(tempString, "Important") Or InStr(tempString, "Moderate") Or InStr(tempString, "Low") Then
                    Range("I" & C).Value = Mid(tempString, 40, InStr(40, tempString, ":") - 41)
                Else
                    Range("I" & C).Value = "No Severity"
                End If
            End If
            'If Range("E" & C).Value <> "" Then
            '    Range("J" & C).Value = getCVESeverity(Left((Range("E" & C).Value), 13))
            'End If
        Next C
        
        ActiveSheet.DisplayPageBreaks = displayPageBreaksState
        
    Next N
    
    Application.ScreenUpdating = screenUpdateState
    Application.DisplayStatusBar = statusBarState
    Application.Calculation = calcState
    Application.EnableEvents = eventsState
    
End Sub

Function getMsSeverity(MS) As String
    Dim title As String
    Dim objHttp As Object
    
    Set objHttp = CreateObject("MSXML2.ServerXMLHTTP")
    objHttp.Open "GET", "http://technet.microsoft.com/en-us/security/bulletin/" & MS, False
    objHttp.Send ""

    title = objHttp.ResponseText

    If InStr(1, UCase(title), "<TITLE>") Then
        title = Mid(title, InStr(1, UCase(title), "<TITLE>") + Len("<TITLE>"))
        title = Mid(title, 1, InStr(1, UCase(title), "</TITLE>") - 1)
    Else
        title = ""
    End If

    getMsSeverity = title
End Function

Function getCVESeverity(CVE) As String
    Dim title As String
    Dim objHttp As Object
    
    Set objHttp = CreateObject("MSXML2.ServerXMLHTTP")
    objHttp.Open "GET", "http://web.nvd.nist.gov/view/vuln/detail?vulnId=" & CVE, False
    objHttp.Send ""

    title = objHttp.ResponseText

    If InStr(1, title, "<span class=""label"">CVSS v2 Base Score:</span>") Then
        title = Mid(title, InStr(1, title, "<span class=""label"">CVSS v2 Base Score:</span>"))
        title = Mid(title, 1, InStr(1, title, "</a>") - 1)
        title = Right(title, Len(title) - InStrRev(title, ">"))
    Else
        title = ""
    End If
    
    getCVESeverity = title
End Function

Open in new window

0
Comment
Question by:evilmonkey2148
  • 2
3 Comments
 
LVL 17

Expert Comment

by:bigeven2002
ID: 40007324
Hello,
We have seen the same error for one of our applications.  Not sure if it is relevant, but try changing your default printer to another (preferably local non-network) and then change it back to see if that works.
0
 

Accepted Solution

by:
evilmonkey2148 earned 0 total points
ID: 40027568
This was due to poor programming. Made the program more dynamic but pulling the needed information instead of static variables.
0
 

Author Closing Comment

by:evilmonkey2148
ID: 40039030
didn't do enough code review before submitting the question.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question