Home > Enterprise >  How to execute a vba macro automatically only once at first file opening?
How to execute a vba macro automatically only once at first file opening?

Time:02-18

My use case is the following :

  1. An Excel template which includes some post treatment VBA macro
  2. A Python script that creates an Excel workbook from the above template
  3. Desired process:
  • Run the Python script
  • Open the created workbook under Excel, which automatically run the VBA macro like depicted Add name to the Workbook

    If it is, you call your procedure and toggle the value of the name to False.

    Private Sub Workbook_Open()
        If Evaluate("OpenFirstTime") = True Then
            'Call YourProcedure
            ThisWorkbook.Names("OpenFirstTime").Value = False
        End If
    End Sub
    
  • Related