Hi,
The code below gets triggered before closing workbook but gets bugged.
The code is supposed to open another workbook before closing and clear a cell and then close again, this is granted that other workbook is editable.
Here's the code, I made the fonred where the code gets bugged.
Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Updates database when main wkbk is closed
Application.EnableEvents = False
Application.ScreenUpdating = False
Dim rcell As Long
Dim LRV As Long
Dim Path As String
Path = "\\user\DataBase.xlsx"
Dim DataBaseWb As Workbook: Set DataBaseWb = Workbooks.Open(Path)
Dim wsV As Worksheet: Set wsV = Sheets("OffersV")
If Not DataBaseWb.ReadOnly Then
LRV = wsV.Range("AI" & Rows.Count).End(xlUp).Row
For rcell = 2 To LRV
If wsV.Range("AI" & rcell) = ws.Range("G9") Then
wsV.Range("BN" & rcell) = ""
Exit For
End If
Next rcell
DataBaseWb.Close True
Else
MsgBox "Data base currently in use, retry closing."
Cancel = True
DataBaseWb.Close False
End If
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
Bookmarks