Share via

Exccel Office 365 VBA Run-time Error -2147319767 (80028029)

Anonymous
2019-09-12T20:04:02+00:00

Last week we started randomly getting this error in several files we use to generate our journal entries. This is happening with Insider Build 1910 and Monthly Targeted 1909 builds. It is sporadic though and I'll explain below.

Run-time Error -2147319767 (80028029) 

Automation Error

Invalid forward reference, or reference to uncompiled type.

The code is this:

Sub WriteJournalEntry()

Dim a As Integer, i As Integer

Dim tbl As ListObject

Dim JEFile As String

'\see en20180124vba for more on manipulating tables with VBA.

Set tbl = ActiveSheet.ListObjects("tblExportData")<--The error is here.

JEFile = "\servername\filepath\file.txt"

    ThisWorkbook.Save

    Application.StatusBar = "Building JE Output table..."

    tbl.QueryTable.Refresh BackgroundQuery:=False

    Application.StatusBar = "Writing journal entry file..."

    If Dir(JEFile) <> "" Then

        Open JEFile For Output As #1

        For i = 1 To tbl.Range.Rows.Count

            If i > 1 Then '\skip the header row

                Print #1, tbl.Range.Rows(i) '\ Print doesn't write quotes like Write does

            End If

        Next i

        Close #1

    Else

        MsgBox "Check M: Drive availability", vbOKOnly, "GL Output File Unavailable"

    End If

    Application.StatusBar = "Extracting text file JE code for verification..."

    Sheets("GL Export").ListObjects("JE_String").QueryTable.Refresh BackgroundQuery:=False

Application.StatusBar = False

MsgBox Prompt:="You must now post in the accounting system", Buttons:=vbInformation, Title:="Journal Entry Written"

End Sub

I've highlighted the line that the debugger shows as the error. If I get rid of the "set" statement and replace tbl with ActiveSheet.ListObjects("tblExportData")in the For/Next loop, it runs fine.

This code has been used unchanged for 3 years. It just started breaking this month. The code in our JE file, which at the end of every month, a new file is created by opening last months file and saving as this months. So "20190731 JE.xlsm" is saved as "20190831 JE.xlsm" and so on. We have dozens. The August file broke. So I opened the July file and saved it again as August and it works. I tried restoring the august file via Sharepoint versioning, but even going 1 week back didn't fix it, and it was definitely working in the august file a week ago.

I though it was a one off issue, but then our payroll JE file broke with the same error. It has the exact same code, though a few of the tables have different names. Again, fixed by removing the SET statement and just repeating the full table object everywhere I needed it.

This code is used in 4 different types of files (monthly JE's, cash JE's, payroll JE, Benefits JE). The code is identical, and so far I've had to fix 2 of these, but the other two types are working fine.

And it is odd to me that both Insider and Monthly Targeted broke at the same time, or appeared to. I have no clue what bug might have been fixed and pushed out to both builds at the same time, or why not all code doing the same thing hasn't broken.

I can share a broken file with an MS employee directly, but wont' post here for confidentiality purposes.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

3 answers

Sort by: Most helpful
  1. Anonymous
    2019-09-24T13:33:20+00:00

    I had the exact same issue while declaring a listobject.  I looked around google for a while to no avail.   So I decided to work my way backward.  Basically, I have a quick solution but I have no idea why the original code did not function.

    So the solution I found is to declare the sheet separately:

    Dim mySh as Worksheet

    Dim myTbl as listobject

    Set mySh = Thisworkbook.Worksheets("SheetName")

    Set myTbl = mySh.listobjects("TableName")

    This works while this:

    Dim myTbl as listobject

    Set myTbl = Thisworkbook.Worksheets("SheetName").listobjects("TableName")

    Does not...

    Your code should work if you do this:

    Sub WriteJournalEntry()

    Dim a As Integer, i As Integer

    Dim sht as worksheet  '***** change 1 ****

    Dim tbl As ListObject

    Dim JEFile As String

    '\see en20180124vba for more on manipulating tables with VBA.

    Set sht = activesheet ' ****** change 2 *****

    Set tbl = sht.ListObjects("tblExportData")'***** change 3 *****

    Was this answer helpful?

    100+ people found this answer helpful.
    0 comments No comments
  2. Anonymous
    2019-09-24T17:03:45+00:00

    That did indeed fix the issue. Thanks again for the suggestion.

    Was this answer helpful?

    20+ people found this answer helpful.
    0 comments No comments
  3. Anonymous
    2019-09-24T14:05:51+00:00

    Thanks! I'll give it a try.

    This certainly seems to be a bug in VBA. Especially since it was working fine!

    Was this answer helpful?

    10 people found this answer helpful.
    0 comments No comments