Jump to content

@SW_MINIMIZE does not work


Go to solution Solved by yuser,

Recommended Posts

If Excel is the default app for .xlsx files on your PC, then you can just use:

ShellExecute("C:\test\test.xlsx", "", "", "", @SW_MINIMIZE)

if not, then you could try: (assumes excel.exe can be found in the PATH)

ShellExecute("Excel.exe", '"C:\test\test.xlsx"', "", "", @SW_MINIMIZE)

 

 

Edited by TheXman
Link to comment
Share on other sites

Neither of these two options work for me either:

ShellExecute("Excel.exe", '"C:\Users\My User\Desktop\Book1.xlsx"', "", "", @SW_MINIMIZE)
ShellExecute('"C:\Users\My User\Desktop\Book1.xlsx"', "", "", "", @SW_MINIMIZE)

Windows 10 latest, Excel 365.  It opens the file in Excel, but Excel is not minimized. @SW_MAXIMIZE does work.

The only way I can ensure that Excel is minimized is by minimizing it separately:

ShellExecute ("Excel.exe", '"C:\Users\My User\Desktop\Book1.xlsx"', "", "")
WinActivate ("Book1.xlsx - Excel", "")
WinWaitActive ("Book1.xlsx - Excel", "")
Send ("#{DOWN}")

or:

ShellExecute ("Excel.exe", '"C:\Users\My User\Desktop\Book1.xlsx"', "", "")
WinWaitActive ("Book1.xlsx - Excel", "")
WinSetState ("Book1.xlsx - Excel", "", @SW_MINIMIZE)

 

Edited by leuce
Link to comment
Share on other sites

On 7/18/2021 at 3:33 PM, TheXman said:

If Excel is the default app for .xlsx files on your PC, then you can just use:

ShellExecute("C:\test\test.xlsx", "", "", "", @SW_MINIMIZE)

if not, then you could try: (assumes excel.exe can be found in the PATH)

ShellExecute("Excel.exe", '"C:\test\test.xlsx"', "", "", @SW_MINIMIZE)

 

 

 

Neither of them works.  Excel is my default app for .xlsx files on my PC.

Link to comment
Share on other sites

On 8/9/2021 at 10:53 PM, Danp2 said:

@dreivilo47Suggest that you take a look at the help file entry for _Excel_Open

@Danp2I have looked at the help file entry for "_Excel_Open".

This is the code to launch a hidden copy of Excel:

#include <Excel.au3>
Global $bVisible = True
Global $sWorkbook = "C:\test\test.xlsx"
$oWorkbook = _Excel_BookOpen(_Excel_Open($bVisible = False), $sWorkbook)

After that, what to do to minimize the file?

Link to comment
Share on other sites

20 minutes ago, dreivilo47 said:

$oWorkbook = _Excel_BookOpen(_Excel_Open($bVisible = False), $sWorkbook)

This line of code doesn't appear to be correct. I would suggest separating into two lines so that you could check for errors --

#include <Excel.au3>
Global $bVisible = False
Global $sWorkbook = "C:\test\test.xlsx"
Global $oExcel = _Excel_Open($bVisible)
Global $oWorkbook = _Excel_BookOpen($oExcel, $sWorkbook)

I was assuming that all of the related windows are hidden if Excel is launched hidden. Is that incorrect?

Link to comment
Share on other sites

  • Solution

Executing excel with a parameter and running excel THEN opening a file is slightly different. When a workbook is opened directly with a parameter, it's like two windows were handled. The second window does not inhert the minimized flag that was assigned to the initial one. It's just the weird way that excel handles windows. To run a workbook "minimized", you can use this trick to run excel hidden, open a file, minimize the window, then set show flag.

 

#include <Excel.au3>
$sFilePath = "C:\test\test.xlsx"
$sFileName = StringRight($sFilePath,StringLen($sFilePath)-StringInStr($sFilePath,"\",0,-1))
$oExcel = _Excel_Open(0)
$oWorkbook = _Excel_BookOpen($oExcel,$sFilePath)
Do
    Sleep(5)
Until WinExists($sFileName & " - Excel")
WinSetState($sFileName & " - Excel","",@SW_MINIMIZE)
$oExcel.Visible = True

 

Link to comment
Share on other sites

On 8/16/2021 at 9:50 PM, Danp2 said:

This line of code doesn't appear to be correct. I would suggest separating into two lines so that you could check for errors --

#include <Excel.au3>
Global $bVisible = False
Global $sWorkbook = "C:\test\test.xlsx"
Global $oExcel = _Excel_Open($bVisible)
Global $oWorkbook = _Excel_BookOpen($oExcel, $sWorkbook)

I was assuming that all of the related windows are hidden if Excel is launched hidden. Is that incorrect?

Ok, thank you.  No errors here.
"test.xlsx" is hidden, Excel too.  Excel is only visible in the Task Manager.

Link to comment
Share on other sites

On 8/17/2021 at 2:06 AM, yuser said:

Executing excel with a parameter and running excel THEN opening a file is slightly different. When a workbook is opened directly with a parameter, it's like two windows were handled. The second window does not inhert the minimized flag that was assigned to the initial one. It's just the weird way that excel handles windows. To run a workbook "minimized", you can use this trick to run excel hidden, open a file, minimize the window, then set show flag.

 

#include <Excel.au3>
$sFilePath = "C:\test\test.xlsx"
$sFileName = StringRight($sFilePath,StringLen($sFilePath)-StringInStr($sFilePath,"\",0,-1))
$oExcel = _Excel_Open(0)
$oWorkbook = _Excel_BookOpen($oExcel,$sFilePath)
Do
    Sleep(5)
Until WinExists($sFileName & " - Excel")
WinSetState($sFileName & " - Excel","",@SW_MINIMIZE)
$oExcel.Visible = True

 

This is working here.  The code of @leuce too.  My problem is solved.  Thanks for your help and support.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...