Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 90185

Application-defined or object-defined error message after the macro is executed

$
0
0

I've encountered a strange thing: I've joined three workbooks: Personal Data Tracker, Global Tracker and the workbook with pivots and charts. The logic is as it follows: the user clicks on a button after the work is finished so the data is copied to the GL Tracker. Once the change event is triggered in the GL Tracker Table, the last workbook opens, the pivot is refreshed upon the open vent and the wb is closed.

Everything seems to be working fine, however when I run the macro live, at the very end I get an error message about

"Application-defined or object-defined error".

Only OK and Help button displayed, it doesn't make the VBE Open so I could debug it. Would anyone know what it may be happening even if the whole chain works fine? Thank you.

Code from the Personal Tracker:

Sub test()

Dim path As String
Dim wb As Workbook

path = ThisWorkbook.path & "\Dest.xlsm"

Application.ScreenUpdating = False

ThisWorkbook.Sheets("Total").Range("R1").Value = Date
Range("R1").Font.Color = VBA.ColorConstants.vbWhite
Worksheets("TOTAL").Range("B2:B13").Copy

On Error GoTo Handler
Workbooks.Open (path)
On Error GoTo 0

Set wb = Workbooks("Dest")
Worksheets("Sheet1").Range("B2").PasteSpecial Paste:=xlPasteValues
Exit Sub

Handler:
 MsgBox "Someone else is saving their data at the moment."& vbNewLine & _
    "Please try in a few seconds"
End Sub

Code from the GL Tracker:

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

Dim MRange As Range
Dim wbPivot As Workbook
Dim pt As PivotTable
Dim ws As Worksheet
Dim Name As String
Dim answer As VbMsgBoxResult

Set MRange = ThisWorkbook.Sheets(1).Range("Table1")
Name = Application.UserName

Application.ScreenUpdating = False

If Not Intersect(Target, MRange) Is Nothing Then
    Application.EnableEvents = True
Set wbPivot = Workbooks.Open("C:\Users\jakub\Desktop\Excel - various\Pivot.xlsm")
End If

'refresh

For Each ws In wbPivot.Worksheets
    For Each pt In ws.PivotTables
        pt.PivotCache.Refresh
        pt.Update
        pt.RefreshTable
    Next
Next

'saving

Application.ScreenUpdating = True

If Application.UserName <> "Jakub Tracz" Then
    MsgBox "User not authorised. Workbook will be closed."
            wbPivot.Close True
            ThisWorkbook.Close True
    Else
        answer = MsgBox(Prompt:="Do you want to save and close the workbook?", _
            Buttons:=vbYesNo + vbQuestion)

    Select Case answer
        Case vbYes
            wbPivot.Close True
            ThisWorkbook.Close True
        Case vbNo
            MsgBox "Welcome, "& Application.UserName
    End Select
End If
End Sub

Viewing all articles
Browse latest Browse all 90185

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>