Sign in to follow this  
Followers 0
MvL

Getting the right Excel window, using ObjGet

1 post in this topic

If $o_Result.Application.Activewindow.Caption <> $ExcelFilename Then

$o_Result.Application.Windows($ExcelFilename).Activate

EndIf

This snippet activates the correct Excel Window of the Excel object,

similar to the additional code I offered for _ExcelBookAttach() in the topic 'Excel Book Attach Problem'

In all:

AutoItSetOption("MustDeclareVars", 1) ; 0=No, 1=Variables must be declared.
Local $o_Result, $PathArr, $ExcelFilename
Local $s_string = "C:\yy.xls" ; Already open, or to be opened.

$o_Result = ObjGet($s_string)
If @error Or Not IsObj($o_Result) Then
 MsgBox(4096, "Error on Workbook", $s_string & " does not exist")
Else
 $o_Result.Windows(1).Visible = 1; Set the worksheet in the workbook visible
 $o_Result.Application.Visible = 1; Set the application visible
 $PathArr = StringSplit($s_string, "\")
 $ExcelFilename = $PathArr[$PathArr[0]]
 If $o_Result.Application.Activewindow.Caption <> $ExcelFilename Then
  $o_Result.Application.Windows($ExcelFilename).Activate ; point to this Excel file
 EndIf
EndIf
Exit

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
Sign in to follow this  
Followers 0