Duplicate spreadsheet

Asked

Viewed 32 times

0

Hello, I have a spreadsheet that contains some important data, I wonder if there is any to duplicate this spreadsheet automatically, so that I manipulate the data in a spreadsheet and when click to save it already save a backup of it, without having to make the changes manually...

1 answer

1

In the two-click project tree in Stables. Then at the top of the combobox from the left select Workbook, it is to be expected that automatically appears this:

Private Sub Workbook_Open()

End Sub

If this does not appear, just select on combobox right to function Open. And add the function as described below.

Private Sub Workbook_Open()
    planilha_backup
End Sub

Create a new module and insert this function

Option Explicit
Option Private Module

Function planilha_backup()
    Dim str_nome_da_pasta_de_trabalho As String
    Dim str_caminho_da_pasta_de_trabalho As String
    Dim str_data_hora As String
    Dim diretorio As String
    str_data_hora = Replace(Date, "/", "-") & "_" & Hour(Now) & Minute(Now) & Second(Now) & "_"
    str_nome_da_pasta_de_trabalho = ActiveWorkbook.Name
    str_caminho_da_pasta_de_trabalho = ActiveWorkbook.Path
    diretorio = str_caminho_da_pasta_de_trabalho & "\" & "bkp_" & str_data_hora & str_nome_da_pasta_de_trabalho

    ActiveWorkbook.SaveAs Filename:= _
        diretorio, FileFormat:= _
        xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False

    str_nome_da_pasta_de_trabalho = ""
    str_caminho_da_pasta_de_trabalho = ""
    str_data_hora = ""
    diretorio = ""
End Function

Browser other questions tagged

You are not signed in. Login or sign up in order to post.