# Start Excel 2013 Minimized from a Command Window

**URL:** <https://boards.straightdope.com/t/start-excel-2013-minimized-from-a-command-window/820048>\
**Category:** Factual Questions\
**Created:** [August 22, 2018, 1:37pm UTC](https://boards.straightdope.com/t/start-excel-2013-minimized-from-a-command-window/820048 "2018-08-22T13:37:49Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![RitterSport](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/rittersport/32/6326_2.png) [@RitterSport](https://boards.straightdope.com/u/RitterSport)\
**Post date:** [August 22, 2018, 1:37pm UTC](https://boards.straightdope.com/t/start-excel-2013-minimized-from-a-command-window/820048/1 "2018-08-22T13:37:49Z")

</div>

Hello!

I have some automated processes that use an Excel auto\_open sub to kickstart various things. Excel is called from a batch file triggered by a Task from the Task Scheduler.

Since auto\_open can be a pain (I don’t want it to run every time the spreadsheet is opened, only when triggered by the batch file), I have it first check whether Excel is minimized, and if so, run whatever it’s supposed to do.

I do this with this command from a command window (or, technically, a batch file):

start /min excel \<file name\>

In Excel 2010, no problem, it opened minimized (Application.WindowState = xlMinimized). Over the weekend, we were upgraded to Office 2013 and this no longer works.

If I type:

start /min winword

Word opens minimized. Same with PowerPoint, etc. However, Excel doesn’t. Maybe it’s related to how Excel now opens each window in its own instance?

Anyway, any ideas as to how to solve this problem? Either a more reliable way to open Excel minimized or some other neat workaround using auto\_open?

I’m using Windows 7 and Office 2013. Thanks!

---

<div class="post-metadata">

**Author:** ![Quartz](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/quartz/32/267_2.png) [@Quartz](https://boards.straightdope.com/u/Quartz)\
**Post date:** [August 22, 2018, 3:20pm UTC](https://boards.straightdope.com/t/start-excel-2013-minimized-from-a-command-window/820048/2 "2018-08-22T15:20:41Z")

</div>

Hmm… I’ve just tried it here - Windows 10, Excel 2013 - and Excel starts minimised using START /MIN

So it’s VBA, not DOS.

According to [this post](https://stackoverflow.com/questions/22564492/excel-application-windowstate-not-behaving-vba), you need to use

> [@](#):
>
> Set wb = Application.Workbooks.Add  
> windows(wb.name).windowstate=xlminimized

---

<div class="post-metadata">

**Author:** ![TroutMan](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/troutman/32/6721_2.png) [@TroutMan](https://boards.straightdope.com/u/TroutMan)\
**Post date:** [August 22, 2018, 3:33pm UTC](https://boards.straightdope.com/t/start-excel-2013-minimized-from-a-command-window/820048/3 "2018-08-22T15:33:48Z")

</div>

I don’t think that solution works. If I’m understanding correctly, **RitterSport** doesn’t want the document to open minimized all the time, but only when opened from the batch file.

You’re right that Excel 2013 and beyond don’t pay attention to the /min switch if you are opening a document (it does if you just open Excel without a document, but that doesn’t help you).

I think you might be able to make it work by passing a parameter in the command line. Then check for that parameter in your VBA instead of checking if it opened minimized.

---

<div class="post-metadata">

**Author:** ![Quartz](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/quartz/32/267_2.png) [@Quartz](https://boards.straightdope.com/u/Quartz)\
**Post date:** [August 22, 2018, 4:05pm UTC](https://boards.straightdope.com/t/start-excel-2013-minimized-from-a-command-window/820048/4 "2018-08-22T16:05:22Z")

</div>

> [@TroutMan](#):
>
> You’re right that Excel 2013 and beyond don’t pay attention to the /min switch if you are opening a document (it does if you just open Excel without a document, but that doesn’t help you).

Excel does obey the /min switch. I’ve just tried START /MIN EXCEL.EXE d20.xls and START /MIN EXCEL d20.xls and both started minimised for me with the spreadsheet loaded.

**RitterSport** , you can test this by trying START /MIN EXCEL.EXE /s to start Excel in Safe Mode. Try this with and without a test spreadsheet.

---

<div class="post-metadata">

**Author:** ![Quartz](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/quartz/32/267_2.png) [@Quartz](https://boards.straightdope.com/u/Quartz)\
**Post date:** [August 22, 2018, 4:10pm UTC](https://boards.straightdope.com/t/start-excel-2013-minimized-from-a-command-window/820048/5 "2018-08-22T16:10:55Z")

</div>

> [@TroutMan](#):
>
> I don’t think that solution works. If I’m understanding correctly, **RitterSport** doesn’t want the document to open minimized all the time, but only when opened from the batch file.

Yes, but the same technique can be used to check.

Anyway, I’ve just had another thought: is it possible that another instance of Excel is already running? If so, the /x switch should be applied as in START /MIN EXCEL.EXE /X XYZ.XLS.

---

<div class="post-metadata">

**Author:** ![TroutMan](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/troutman/32/6721_2.png) [@TroutMan](https://boards.straightdope.com/u/TroutMan)\
**Post date:** [August 22, 2018, 4:15pm UTC](https://boards.straightdope.com/t/start-excel-2013-minimized-from-a-command-window/820048/6 "2018-08-22T16:15:08Z")

</div>

I see the same behavior as the OP. With no filename, it opens minimized. If I include a filename, it does not. This is with Excel 2016.

---

<div class="post-metadata">

**Author:** ![RitterSport](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/rittersport/32/6326_2.png) [@RitterSport](https://boards.straightdope.com/u/RitterSport)\
**Post date:** [August 22, 2018, 4:30pm UTC](https://boards.straightdope.com/t/start-excel-2013-minimized-from-a-command-window/820048/7 "2018-08-22T16:30:18Z")

</div>

**Quartz** , I don’t know what to tell you, it doesn’t work for me like that, even without a spreadsheet parameter.

**TroutMan** , as I mention, it starts non-minimized whether I include a spreadsheet to open or not. I just checked and there is no other Excel process open.

Anyway, I continued to investigate and I independently found the command line parameter version. First, I tried setting an environment variable, but Excel never seemed to see them (either when opening directly from a command window or typing “start…” from a command window. I mention that because it’s possible that “start” creates a different environment with different variables.

After multiple failed attempts, crashing Excel over and over again, I finally got it working. From the batch file, I include a parameter, Excel sees it, and runs if it’s the right one. If you’re interested, I can post the code or send it via PM.

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![Quartz](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/quartz/32/267_2.png) [@Quartz](https://boards.straightdope.com/u/Quartz)\
**Post date:** [August 22, 2018, 4:43pm UTC](https://boards.straightdope.com/t/start-excel-2013-minimized-from-a-command-window/820048/8 "2018-08-22T16:43:37Z")

</div>

> [@RitterSport](#):
>
> **Quartz** , I don’t know what to tell you, it doesn’t work for me like that, even without a spreadsheet parameter.

No problem. I am on Windows 10, not 7, so the issue may well be that.

---

<div class="post-metadata">

**Author:** ![TroutMan](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/troutman/32/6721_2.png) [@TroutMan](https://boards.straightdope.com/u/TroutMan)\
**Post date:** [August 22, 2018, 5:15pm UTC](https://boards.straightdope.com/t/start-excel-2013-minimized-from-a-command-window/820048/9 "2018-08-22T17:15:12Z")

</div>

> [@Quartz](#):
>
> No problem. I am on Windows 10, not 7, so the issue may well be that.

There are so many configurations and versions between Excel and Windows, we could spend days or weeks trying to figure out the cause of the different behavior.

Glad you found a solution, **RS**. I crashed Excel multiple times trying to test out some sample code. I assumed it was a permissions issue with a kernel command (I’m not a local admin on my work machine), but maybe it’s just buggy.

---

<div class="post-metadata">

**Author:** ![RitterSport](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/rittersport/32/6326_2.png) [@RitterSport](https://boards.straightdope.com/u/RitterSport)\
**Post date:** [August 22, 2018, 5:24pm UTC](https://boards.straightdope.com/t/start-excel-2013-minimized-from-a-command-window/820048/10 "2018-08-22T17:24:21Z")

</div>

> [@TroutMan](#):
>
> There are so many configurations and versions between Excel and Windows, we could spend days or weeks trying to figure out the cause of the different behavior.
> 
> Glad you found a solution, **RS**. I crashed Excel multiple times trying to test out some sample code. I assumed it was a permissions issue with a kernel command (I’m not a local admin on my work machine), but maybe it’s just buggy.

It was crashing for me because it turns out you have to declare extra functions, not just GetEnvVar. These are the functions I had to declare to get it to stop crashing:

* * *

Private Declare Function GetEnvVar Lib “kernel32” Alias “GetEnvironmentVariableA” (ByVal lpName As String, ByVal lpBuffer As String, ByVal nSize As Long) As Long

Declare Function GetCommandLine Lib “kernel32” Alias “GetCommandLineW” () As Long

Declare Function lstrlenW Lib “kernel32” (ByVal lpString As Long) As Long

## Declare Sub CopyMemory Lib “kernel32” Alias “RtlMoveMemory” (MyDest As Any, MySource As Any, ByVal MySize As Long)

Of course, I didn’t figure that out myself, it was buried multiple posts down in some thread on the subject. GetCommandLine returns a long which has to be converted to a string using CopyMemory – I think the long is a pointer and you’re dumping memory. This seems all seems so dangerous and hackable to me.

---

<div class="post-metadata">

**Author:** ![Melbourne](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@Melbourne](https://boards.straightdope.com/u/Melbourne)\
**Post date:** [August 23, 2018, 12:15pm UTC](https://boards.straightdope.com/t/start-excel-2013-minimized-from-a-command-window/820048/11 "2018-08-23T12:15:53Z")

</div>

> [@RitterSport](#):
>
> Anyway, any ideas as to how to solve this problem? Either a more reliable way to open Excel minimized or some other neat workaround using auto\_open?

If I understand correctly, you have a spreadsheet with an auto-runs macro, that on startup checks if – some condition – is true, and if so runs – some code --.

The alternative approach is to move the relevant code from the auto-runs macro into a separate macro, and, when desired, run the separate macro with a separate command.

There are three well-known ways of getting Excel to run a separate command: SendKeys, DDE, and COM. Discounting SendKeys and DDE, script to run a specific macro would look something like this:

Dim xl as object  
Set xl = CreateObject(“Excel.Application”)  
xl.Workbooks.Open (“C:\fred.xlsm”)  
xl.Visible = True  
xl.Run “MyMacro”

if you don’t like Windows Scripts, (js or vbs) you can do the same thing use Powershell. If you /need/ to use a .bat or .cmd file, you can do something similar using DDE.

---

<div class="post-metadata">

**Author:** ![RitterSport](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/rittersport/32/6326_2.png) [@RitterSport](https://boards.straightdope.com/u/RitterSport)\
**Post date:** [August 23, 2018, 1:06pm UTC](https://boards.straightdope.com/t/start-excel-2013-minimized-from-a-command-window/820048/12 "2018-08-23T13:06:15Z")

</div>

> [@Melbourne](#):
>
> If I understand correctly, you have a spreadsheet with an auto-runs macro, that on startup checks if – some condition – is true, and if so runs – some code --.
> 
> The alternative approach is to move the relevant code from the auto-runs macro into a separate macro, and, when desired, run the separate macro with a separate command.
> 
> There are three well-known ways of getting Excel to run a separate command: SendKeys, DDE, and COM. Discounting SendKeys and DDE, script to run a specific macro would look something like this:
> 
> Dim xl as object  
> Set xl = CreateObject(“Excel.Application”)  
> xl.Workbooks.Open (“C:\fred.xlsm”)  
> xl.Visible = True  
> xl.Run “MyMacro”
> 
> if you don’t like Windows Scripts, (js or vbs) you can do the same thing use Powershell. If you /need/ to use a .bat or .cmd file, you can do something similar using DDE.

Thanks, **Melbourne**! As I mention above, I got it working using a command line argument and I’m going to leave well enough alone. Given how restrictive our environment is here, we probably have VBS turned off or something anyway.

---

<div class="post-metadata">

**Author:** ![Melbourne](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@Melbourne](https://boards.straightdope.com/u/Melbourne)\
**Post date:** [August 25, 2018, 1:45am UTC](https://boards.straightdope.com/t/start-excel-2013-minimized-from-a-command-window/820048/13 "2018-08-25T01:45:13Z")

</div>

> [@RitterSport](#):
>
> Thanks, **Melbourne**! As I mention above, I got it working using a command line argument and I’m going to leave well enough alone. Given how restrictive our environment is here, we probably have VBS turned off or something anyway.

🙂 If cscript is not installed, _you can do the same thing using autoruns in another spreadsheet_ Your batch file loads the command spreadsheet, and the command spreadsheet loads and executes macros in the data spreadsheet.

I’m just putting it out there 🙂 don’t break anything that is already working.

---

<div class="post-metadata">

**Author:** ![RitterSport](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/rittersport/32/6326_2.png) [@RitterSport](https://boards.straightdope.com/u/RitterSport)\
**Post date:** [August 25, 2018, 2:14am UTC](https://boards.straightdope.com/t/start-excel-2013-minimized-from-a-command-window/820048/14 "2018-08-25T02:14:03Z")

</div>

> [@Melbourne](#):
>
> 🙂 If cscript is not installed, _you can do the same thing using autoruns in another spreadsheet_ Your batch file loads the command spreadsheet, and the command spreadsheet loads and executes macros in the data spreadsheet.
> 
> I’m just putting it out there 🙂 don’t break anything that is already working.

It’s funny because I already have some spreadsheets that run VBA code in a different spreadsheet, but that never occurred to me. That would definitely work – auto\_run in one spreadsheet that opens the main spreadsheet and runs the DoItAll function there. However, since I already have it working, I’m leaving it. Plus, getting the first spreadsheet right would be annoying, because auto\_run functions are a pain if they run without conditions – you always have to remember to open that spreadsheet with ctrl (or shift? whatever).
