[Solved] VBA Code Added Excel File Not Work Re-open Time

Muh

New member
Created a New VBA Excel File .Code Added In This File . But After Closing And Re-open Time This Code Features Not Affect In Excel File . also File Saved This Format "Excel Macro-Enabled Workbook (*.Xlsm) ". But Not Work Re-open Time.

Need While This Worksheet Open Time Automatically Code Features Run In Excel File .

Please let The Process of File Saving Method.
 
Hello Muh,

It sounds like the VBA code is not being triggered when you reopen the workbook. To ensure your code runs automatically when the workbook is opened, you need to place the code in the ThisWorkbook object in the VBA editor, specifically in the Workbook_Open event. Here's how you can do it:
  • Press Alt + F11 to open the VBA editor.
  • In the Project Explorer, find ThisWorkbook under your workbook.
  • Double-click ThisWorkbook to open its code window.
Paste the following code:
Code:
Private Sub Workbook_Open()
    ' Your code goes here
End Sub
  • Save the workbook as a macro-enabled file (.xlsm).
  • Close and reopen the file, and the code should run automatically when the workbook is opened.
Make sure that macros are enabled in Excel for this to work. Let me know if you need more help!
 
Not Worked After Re-Open .Can Let me Step by step the Process.

Code added- ThisWorkbook
File Format -macro-enabled file (.xlsm).

Can Let me Step by step the Process.
 
Hello Muh,

I understand you're still facing issues getting your VBA code to run automatically upon reopening the workbook. Let's walk through the process step by step to ensure everything is set up correctly:

Step 1: Open the VBA Editor
  1. Open your workbook.
  2. Press Alt + F11 to open the VBA Editor.
Step 2: Add Code to the Workbook_Open Event
  1. In the Project Explorer (usually on the left side), locate your workbook.
  2. Expand your workbook's folder if it's collapsed.
  3. Double-click on ThisWorkbook.
  4. In the code window, enter the following:
Code:
Private Sub Workbook_Open()
' Place your VBA code here
MsgBox "Welcome! This macro runs automatically when the workbook opens."
End Sub

Step 3: Save the Workbook
  1. Press Ctrl + S.
  2. Choose Excel Macro-Enabled Workbook (*.xlsm) if prompted.
Step 4: Enable Macros
  1. Close the workbook.
  2. Reopen the workbook.
  3. When prompted, ensure macros are enabled. If you don't see the prompt:
    • Go to File > Options > Trust Center > Trust Center Settings.
    • Select Macro Settings and ensure Enable all macros are checked.
Step 5: Test the Code
Upon reopening the workbook, the message box should appear, confirming that the Workbook_Open event is working.

Let me know if this resolves the issue or if further assistance is needed!
 

Online statistics

Members online
0
Guests online
7
Total visitors
7

Forum statistics

Threads
378
Messages
1,653
Members
713
Latest member
Akram Hassan
Back
Top