Jump to content
Sign in to follow this  

Getting the right Excel window, using ObjGet

Recommended Posts

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



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")
 $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

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...