When you create a new workbook in Excel using VBA, it typically opens in a maximized or visible window, which can disrupt your workflow—especially if you're running multiple automated tasks. Minimizing it keeps the interface clean, prevents accidental interaction, and allows background processing to proceed smoothly. This is achieved by setting the WindowState property of the new workbook's window to xlMinimized immediately after creation. No special tools or permissions are required beyond Excel with VBA enabled.

What You'll Need

  • Microsoft Excel (any version from 2010 onward, including Microsoft 365)
  • VBA enabled (ensure the Developer tab is visible or open the VBA editor via Alt + F11)
  • A basic understanding of VBA syntax and workbook objects

Step-by-Step

  1. Open Excel and press Alt + F11 to launch the Visual Basic for Applications (VBA) editor. If the Developer tab is visible in Excel, you can also click Visual Basic there instead.
  2. In the VBA editor, go to Insert > Module to create a new standard module. This is where your macro code will live.
  3. Enter the following VBA code into the module window:
    Sub CreateAndMinimizeNewWorkbook()
        Dim newWb As Workbook
        Set newWb = Workbooks.Add
        newWb.WindowState = xlMinimized
    End Sub
    This code declares a Workbook object, creates a new blank workbook using Workbooks.Add, and then sets its window state to minimized.
  4. Ensure xlMinimized is written exactly as shown—VBA recognizes this built-in constant. Do not replace it with a raw number like -4140 unless you're intentionally using the numeric value (not recommended for readability).
  5. Place your cursor anywhere inside the CreateAndMinimizeNewWorkbook procedure, then press F5 to run it. Alternatively, return to Excel, go to the Developer tab, click Macros, select your macro, and click Run.
  6. Observe the result: Excel opens a new workbook (you may briefly see it appear), then immediately minimizes it to the taskbar. The original workbook remains active and visible.

Common Mistakes

  • Using Application.WindowState = xlMinimized instead of newWb.WindowState—this minimizes the entire Excel application window, not just the new workbook, which may not be desirable.
  • Forgetting to qualify the workbook object. Writing WindowState = xlMinimized without a leading object reference (e.g., newWb.) will cause a compile error because VBA won’t know which window to minimize.
  • Running the macro while Excel itself is already minimized, which can lead to confusing behavior where the new workbook appears briefly or fails to minimize as expected.
  • Assuming Workbooks.Add returns a minimized window by default—it doesn’t; it opens visible by default unless you explicitly change the window state.
  • Not saving the workbook as a macro-enabled file (.xlsm) if you intend to reuse the macro later. Standard .xlsx files will strip VBA code upon saving.

Tips

  • For batch operations—like creating multiple temporary workbooks—loop through the creation and minimization to keep all new files out of the way. Example:
    For i = 1 To 3
        Workbooks.Add.WindowState = xlMinimized
    Next i
  • Use newWb.Activate before minimizing if you need to perform operations on the new workbook first (e.g., setting sheet names or writing initial data), then minimize it before returning focus to the original workbook.
  • Combine minimization with error handling to ensure the window is restored if something goes wrong:
    On Error GoTo ErrHandler
    Set newWb = Workbooks.Add
    newWb.WindowState = xlMinimized
    Exit Sub
    ErrHandler:
        If Not newWb Is Nothing Then newWb.Close SaveChanges:=False
        MsgBox "Error: " & Err.Description
  • Consider using xlNormal instead of xlMinimized if you want the workbook to open in a standard, non-maximized window but still avoid full-screen takeover.
  • Test your macro in a blank workbook first. Some add-ins or Excel settings (e.g., custom startup files) can override default window behavior.

Troubleshooting

If the new workbook does not minimize as expected, follow these checks in order:

  1. Verify Excel is not already minimized. If Excel itself is minimized when you run the macro, the new workbook may inherit that state or behave unpredictably. Restore Excel to a normal or maximized window, then rerun the macro.
  2. Check for conflicting add-ins. Some Excel add-ins (e.g., Power Query, third-party tools) can intercept window events. Start Excel in Safe Mode (hold Ctrl while clicking Excel in the Start menu) and test the macro there. If it works in Safe Mode, disable add-ins one by one to identify the culprit.
  3. Confirm the constant is spelled correctly. xlMinimized is case-insensitive, but typos like xlMinimised (British spelling) or xlMinimize will cause errors. Use the VBA editor’s Auto List Members feature: type newWb. and press Ctrl + J to see available properties and constants.
  4. Ensure the workbook object is valid. If Workbooks.Add fails (e.g., due to corrupted templates or disk issues), newWb may be Nothing. Wrap the code in error handling and add a debug statement: Debug.Print newWb.Name before minimizing to confirm the object was created.
  5. Check macro security settings. Go to File > Options > Trust Center > Trust Center Settings > Macro Settings and ensure Enable all macros (not recommended for production) or Disable all macros with notification is selected. If macros are disabled, the code won’t run at all.
  6. Try an alternative approach for stubborn cases. If minimization still fails, force Excel to refresh the window state with:
    newWb.Activate
    Application.Wait Now + TimeValue("00:00:01")
    newWb.WindowState = xlMinimized
    ThisWorkbook.Activate
    This briefly activates the new workbook, waits one second (to allow UI updates), minimizes it, then returns focus to the original workbook.

Frequently Asked Questions

Can I minimize a specific workbook instead of a newly created one?

Yes—replace Workbooks.Add with a reference to an existing workbook, like Workbooks("SalesData.xlsx").WindowState = xlMinimized. Ensure the workbook name is exact, including the file extension if visible.

Does minimizing the workbook affect its macros or calculations?

No. Minimizing only changes the window’s visibility. Background processes, data connections, and scheduled macros continue to run normally.

Why does the workbook still flash briefly before minimizing?

This is normal behavior. Excel must briefly render the new workbook window before applying the minimized state. It’s harmless and cannot be avoided without using Windows API calls, which are unnecessary for standard automation.

Can I minimize the workbook but keep it in the foreground?

No. xlMinimized always hides the window and places it on the taskbar. To keep it visible but non-intrusive, use xlNormal and resize it (e.g., newWb.Windows(1).Width = 300).

What’s the difference between WindowState and ActiveWindow?

WindowState is a property of a workbook’s window (e.g., minimized, maximized, normal). ActiveWindow refers to the currently focused window in Excel’s window collection. For a single workbook, they align—but with multiple workbooks open, always qualify with the specific workbook object (e.g., newWb.Windows(1).WindowState) to avoid ambiguity.

Will this work on Mac?

Partially. Excel for Mac supports WindowState, but xlMinimized may not minimize to a dock or taskbar (Mac doesn’t have one). It typically collapses the window to the title bar area. Test thoroughly on your version.