auto close

PIsabel

Board Regular
Joined
Feb 4, 2014
Messages
126
Office Version
  1. 365
Platform
  1. Windows
Hello.
I am trying to create a macro that every time I close the file the macro makes a copy of that file.
So far I have this but it still does not work well.
Someone can help me?

Thank you, Isabel


Code:
Sub auto_close()
    If ThisWorkbook.Path = "[URL="file://\\Servidor\servidor\ORÇAMENTOS\orç"]\\Servidor\servidor\ORÇAMENTOS\orç[/URL] - A Fazer" Then
    Opções.Show
   
    If Sheets("PVP").Visible = True Then
    thisfile = Range("e3") & (" - nº ") & Range("I2") & " - " & Format(Now, "yyyy-mm-dd hh-mm")
    ActiveWorkbook.SaveAs Filename:="[URL="file://\\Servidor\servidor\Arquivo"]\\Servidor\servidor\Arquivo[/URL] orçamentos\Seguranças" & thisfile
    
    If Sheets("Profissional").Visible = True Then
    thisfile = "- Orçamento - profissional - " & Range("e3") & " - nº " & Range("j2") & " - " & Range("e8") & " - " & Format(Now, "yyyy-mm-dd hh-mm")
    ActiveWorkbook.SaveAs Filename:="[URL="file://\\Servidor\servidor\Arquivo"]\\Servidor\servidor\Arquivo[/URL] orçamentos\Seguranças" & thisfile
    
    End If
    End If
    End If
    
End Sub
 
Last edited:

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
To have the code run when you close the file it would need to be a before close event. The code would have to go into the ThisWorkbook. How is you code not working well?

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)

[COLOR=#008000]'code to run before close goes here[/COLOR]

end sub
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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