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
 
Are you sure that you don't have On Error Resume Next somewhere in your code? You haven't posted all of it.
 
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Maybe that
Code:
SaveChanges:=True
to be the problem?
If already save once it`s not doing the save as?
 
Upvote 0
I don't know, but the Before_Close event fires before the workbook is closed so there shouldn't be any changes to save.
 
Upvote 0
I`m sure.I`m new in VBA(I think that you saw that) and I don`t know how to use On Error Resume Next ,so I don`t have something like this in my code.
Sorry for a lot of questions, for bothering you and for my English that is not so good...
 
Upvote 0
A very strange thing is that I try to copy exactly the same code in the Workbook Open event and it`s saving on the site , but now doesn`t make the others operations from the event,like copy some rows!
When I checked with debbuger the information was copied, but when I open the file is not there.
And another strange thing, I`m trying to delete the code from Workbook Open, I save the file, but when I reopen the file the code is again there.How this is posible?
 
Last edited:
Upvote 0
Ok,thanks.
Maybe it`s another way to save as the file on the site with another event or another code?
 
Upvote 0
Thank you a lot!!!
I put this code in the excel file that open and close automatically that file that I need to save as on the site and it`s seems like is working!
Code:
Workbooks("DatabaseLealde1").Save
Dim thefile, thepath As String
Let thepath = "[URL="http://teamwork.tenaris.net/sites/quality_Silcotub/Quality%20System/CapabilityAnalysis/CPKDimensional/DB/"]http://[/URL]the link"
Let thefile = "DatabaseLealde1.xlsm"
    Workbooks("DatabaseLealde1").SaveAs Filename:=thepath & thefile _
        , FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
Workbooks("DatabaseLealde1").Close SaveChanges:=True
 
Upvote 0

Forum statistics

Threads
1,214,944
Messages
6,122,384
Members
449,080
Latest member
Armadillos

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