Workbook_BeforeClose question

Adi21

Board Regular
Joined
Aug 11, 2014
Messages
62
Hy guys, I have a problem with the Workbook_BeforeClose.
I wrote a code and I want for every time when I close the file, this file to be saved on a site.
When I open the file myself and closed it is working. But that file is opened from another Excel file to complete cells and here is not working anymore. The Workbook_BeforeClose works only when I open myself the file and is not working if it`s automaticly open and close by another file?
I don`t understand why, because I have Private Sub Workbook_Open() in the file and this is working in the both situations.
Thank you.
Here is the code, if helps:
Code:
rivate Sub Workbook_BeforeClose(Cancel As Boolean)
Dim thefile, thepath As String
Let thepath = "[URL]http://....etc.../[/URL]"
Let thefile = "DatabaseLealde1.xlsm"
    ActiveWorkbook.SaveAs Filename:=thepath & thefile _
        , FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
I changed, but the same thing, is working if I open and close the file, but if the another excel open and close it, nothing hapens.
 
Upvote 0
I checked with the debugger and is travel through all the lines from Sub Workbook_BeforeClose but nothing happens.
Maybe is the Save As function the problem? That you wanted to say Andrew?
But replacing ActiveWorkbook with ThisWorkbook doesn`t resolve the problem.
 
Upvote 0
I think no. Here is the code that open and close that file:

Code:
Workbooks.Open Filename:=ThisPath & "\" & "BazaDeDate" & "\" & "DatabaseLealde1"
'here is the code to copy some rows
Workbooks("DatabaseLealde1").Close SaveChanges:=True
 
Upvote 0
Is the Workbook_BeforeClose event actually firing when you run your code? Why don't you have file extensions?
 
Upvote 0
I checked with the debbuger and yes, Workbook_BeforeClose event is running.
Your refer like this?
Code:
Workbooks.Open Filename:=ThisPath & "\" & "BazaDeDate" & "\" & "DatabaseLealde1.xlsm"
 
Upvote 0
This is what I was thinking too. But it`s not working.The debbuger evaluets the line but nothing hapens.
 
Upvote 0

Forum statistics

Threads
1,214,388
Messages
6,119,226
Members
448,878
Latest member
Da9l87

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top