Home » excel » excel – VBA Run-time error -2147319767 (80028029)

excel – VBA Run-time error -2147319767 (80028029)

Posted by: admin May 14, 2020 Leave a comment


I’m having problems With my Excel-files/VBA code. I’m updating a lot of Excel files (copy/paste into tables) and updating pivot-tables in these files. I’ve been using this code/Method for years, and it’s been working just fine.

But recently my files has been acting strangely after running VBA. When updating 35 excel files, around 15 of these are “corrupt” after an update. I can open them up, but I can’t store. Then files just shut Down.

So I changed my line “Application.DisplayAlerts = False” into “True”, and ran again. And this time VBA stops displaying:
Run-time error ‘-2147319767 (80028029): Automation error.
And it Points to this line:

For Each pt In sh_ske_beløp.PivotTables

This is just one out of 12 sheets that I update in exactly the same way (entire code is like this):

For Each pt In sh_ske_beløp.PivotTables
Next pt

I’m completely lost! This bit of code should be a no-brainer! And I just can’t figure out what’s wrong. I’m doing the “Option Explicit”-bit at the top, without any errors. I’m not doing anything Advanced, just opening up files and copying/pasting data between workbooks/sheets and updating pivot-tables. There’s no “Userform” going on here. Nothing is “missing” in the Tools/References menu.
The code is running on Windows 10 64-bit using Excel 365 64 bit. Every available update has been installed.

How to&Answers:


try run this code

Sub test()
Dim sht As Worksheet
Dim wb As Workbook
Dim shtName As String
Dim pt As PivotTable
Set wb = ThisWorkbook
shtName = "sh_ske_beløp"
For Each sht In wb.Worksheets
    If sht.Name = shtName Then
        For Each pt In sht.PivotTables
        Next pt
    End If
Next sht
If Not wsExists(shtName, wb) Then MsgBox shtName & " NotExist!!!"
End Sub

Function wsExists(wsName As String, wb As Workbook) As Boolean
Dim ws
    For Each ws In wb.Sheets
        wsExists = (wsName = ws.Name): If wsExists Then Exit Function
    Next ws
End Function

VBA Variables

Variables are specific values that are stored in a computer memory or storage system. Later, you can use that value in code and execute. The computer will fetch that value from the system and show in the output. Each variable must be given a name.

To name the variable in VBA, you need to follow the following rules.

  • It must be less than 255 characters
  • No spacing is allowed
  • It must not begin with a number
  • Period is not permitted
  • No DOT allowed
  • NO Unicode allowed