Jump to content
tauruzian

Activate Excel - Not activating

Recommended Posts

tauruzian

I used this code to get the excel file name and activate the file:

#include <Excel.au3>

Global $oExcel = _Excel_Open()
Global $oWorkbook = $oExcel.ActiveWorkbook
WinActivate($oWorkbook.Name)
Global $sText = WinGetTitle("")
ClipPut($sText &"::" &$oWorkbook.Name)
MsgBox(0,"Test",$sText &"::" &$oWorkbook.Name)

Initially, the code working fine in Window 7 using Excel 2013. When I try to execute the same code in Window XP using Excel 2007, the workbook did not activated.

post-82822-0-44653500-1425284362_thumb.p

Above screen shot shows that the code managed to activate the excel and get the filename in Msgbox (Window 7 and Excel 2013).

post-82822-0-06147000-1425284477.png

Above screen shot shows that the Excel not activated but only show the filename on Msgbox (Window XP and Excel 2007).

Please advice.

Share this post


Link to post
Share on other sites
water

With the new Excel UDF you need to call _Excel_Open to start Excel, then _Excel_BookOpen or _Excel_BookNew to open an existing/create a new workbook.

Automating the Excel GUI is a bad idea. There are COM properties to retrieve the information you need.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
tauruzian

With the new Excel UDF you need to call _Excel_Open to start Excel, then _Excel_BookOpen or _Excel_BookNew to open an existing/create a new workbook.

Automating the Excel GUI is a bad idea. There are COM properties to retrieve the information you need.

How to activate the minimised Excel rather than open a new one.

Share this post


Link to post
Share on other sites
water

Is Excel already running when you start your script?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
tauruzian

Is Excel already running when you start your script?

Yes. But minimised by the user

Share this post


Link to post
Share on other sites
water

Something like this?

#include <Excel.au3>
$oExcel = _Excel_Open()
$sCaption = $oExcel.Caption
WinSetState($sCaption, "", @SW_MAXIMIZE)
  • Thanks 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
tauruzian

 

Something like this?

#include <Excel.au3>
$oExcel = _Excel_Open()
$sCaption = $oExcel.Caption
WinSetState($sCaption, "", @SW_MAXIMIZE)

The code working fine but fail in 1 condition. Let say I highlight some text the cell and minimised the excel and run the code. It does not working.

Share this post


Link to post
Share on other sites
water

Do you mean edit or just select?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
tauruzian

Do you mean edit or just select?

Just select or just click into the cell and minimised the excel. It not working for both (2007 and 2013).

Share this post


Link to post
Share on other sites
water

When a cell is just selected it works fine (because at least a single cell is allways selected = the active cell).

When the cell is in edit mode then I haven't found a way to maximize the window and show thw workbook.

Is it possible to disable edit mode to solve this problem (can be done by the AutoIt script)?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
tauruzian

When a cell is just selected it works fine (because at least a single cell is allways selected = the active cell).

When the cell is in edit mode then I haven't found a way to maximize the window and show thw workbook.

Is it possible to disable edit mode to solve this problem (can be done by the AutoIt script)?

Yes, how do I disable the edit mode?

Share this post


Link to post
Share on other sites
AnonymousX
On 3/2/2015 at 3:32 AM, water said:

Something like this?

#include <Excel.au3>
$oExcel = _Excel_Open()
$sCaption = $oExcel.Caption
WinSetState($sCaption, "", @SW_MAXIMIZE)

Thanks Water, was trying to figure this out

Share this post


Link to post
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

×