Runtime Error 6 - Overflow in Excel VBA When Using Scripting.FileSystemObject

99 Views Asked by At

Hopefully someone can shed some light on a problem that's just cropped up with some code that's been working faultlessly for years.

I have a VBA form and code in a spreadsheet that opens another workbook, writes some data to that workbook then closes it and continues. The code has been working for all users for years now without me touching it. But now I'm getting an Overflow error.

Here's the code that's causing the problem:

Private Sub Check_Installation_Spreadsheet()

    Dim Installation_Spreadsheet_Lock As String
    Dim Installation_Spreadsheet As String
    Dim obj_installWB As Object
    Dim obj_installWS As Object
    Dim objfso As Object
    Dim rowCount As Integer
    Dim MonthYear As String
    Dim FinancialYear As String
    Dim install_Day As String
    Dim Mon_Wed As String
    Dim Wed_Fri As String
    Dim loopcounter As Integer
    Dim exists As Boolean
    Dim strArray() As String
    Dim tmpString As String
    Dim tmpDDStart As String
    Dim tmpInstallDate As Date
    Dim tmp6WeekTrialDate As Date
    
    FinancialYear = Range("FinancialYear")
    
    Installation_Spreadsheet_Lock = "S:\2-SBS\SBS-CustomerAccounts\~$Master installation sheet for finance 2024.xlsx"
    Installation_Spreadsheet = "S:\2-SBS\SBS-CustomerAccounts\Master installation sheet for finance 2024.xlsx"

    Set objfso = CreateObject("Scripting.FileSystemObject")

    If objfso.FileExists(Installation_Spreadsheet) Then
        If objfso.FileExists(Installation_Spreadsheet_Lock) Then
            MsgBox ("The file is locked by " & GetFileOwner(Installation_Spreadsheet_Lock))
            verify_Continue = "No"
            Exit Sub
        Else
            MsgBox ("The file is available")
            Application.ScreenUpdating = False

' *** The next line is the line where the process is failing ***

            Set obj_installWB = Workbooks.Open(Installation_Spreadsheet)

            ThisWorkbook.Activate
            Application.ScreenUpdating = True
            verify_Continue = "Yes"
        End If
    Else ' The master installation spreadsheet doesn't exist
        MsgBox ("The master installation spreadsheet " & Installation_Spreadsheet & " does not exist")
        verify_Continue = "No"
        Exit Sub
    End If

As stated, this code has worked for years without any issue.

The workbook that the code opens had around 8,500 rows in the worksheet being accessed so I tried deleting around half of those but I still got the overflow error.

0

There are 0 best solutions below