Jump to content
Sign in to follow this  
help_me_please

ObjGet using PID

Recommended Posts

help_me_please

I know I've been staring at my script for too long, because I can't figure this out. :mad2:

I want to attach to a specific instance of excel, preferable using the PID.

ObjGet( ) even says that it can attach to an object using a given PID, but I can't get it to work.

A point in the right direction would be greatly appreciated 

Share this post


Link to post
Share on other sites
JLogan3o13

@help_me_please how about showing us this code you're staring at, so we can see just what you're doing? Have you looked at the _Excel_* sections of the help file? You can easily open, create, or edit specific Workbooks with these functions.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
help_me_please

I want to run a macro within an excel workbook, and I've seen that I must call the excel object using "$oExcel.Run("Macro_Name_Here")".

This macro is a pain, as it uses the currently selected cell as a base to begin an interpolation.

To complicate things further, there will be at least one other excel instance open when attempting to run said macro.

Therefore, I need to select a specific excel object to attempt to execute the macro in.

 

It would go this this...

$Excel_Proccess_ID = WinGetProcess("Excel_Workbook_Title_Name_Here")

$Excel_Object = ObjGet("",$Excel_Proccess_ID) ;  < -- This is the problem

$Excel_Object.Run("Macro_Name_Here")

Share this post


Link to post
Share on other sites
Jimwright

Not sure if this helps - i've probvably oversimplified your problem. I've  3 excels open on my laptop, one of them called "ThisExcel.xlsx"  and in that sheet is a macro that just moves the cursor and puts some text in a cell, called Macro1.  This runs it OK:

#include <Excel.au3>
$oExcel=_excel_open()
$oExcel.run("thisexcel.xlsx!Macro1")

Do you not know the name of the spreadsheet at the time it runs ?

Share this post


Link to post
Share on other sites
help_me_please

 

3 minutes ago, Jimwright said:

Not sure if this helps - i've probvably oversimplified your problem. I've  3 excels open on my laptop, one of them called "ThisExcel.xlsx"  and in that sheet is a macro that just moves the cursor and puts some text in a cell, called Macro1.  This runs it OK:

#include <Excel.au3>
$oExcel=_excel_open()
$oExcel.run("thisexcel.xlsx!Macro1")

Do you not know the name of the spreadsheet at the time it runs ?

I do know the name of the excel workbook at the time of run.

when you say that you have 3 excels open, do you have three workbooks within the same instance? or three instances of excel?

check the task manager to verify this.

Share this post


Link to post
Share on other sites
Jimwright
1 minute ago, help_me_please said:

 

I do know the name of the excel workbook at the time of run.

when you say that you have 3 excels open, do you have three workbooks within the same instance? or three instances of excel?

check the task manager to verify this.

I have 3 Excels open in taskmanager

Share this post


Link to post
Share on other sites
help_me_please

The problem is that I have two excel instances open, each with there own workbook, such as (from the task manager)

\/ Microsoft Excel (32bit)

>Workbook2

\/ Microsoft Excel (32bit)

>Workbook1

 

Workbook1 is open initially to read from and write to, and needs to remain open.

Workbook2 is an output that opens in a new instance that the macro needs to run in.

 

When I use

$oExcel = _Excel_Open()

$oExcel.Run("Workbook2.xlsm!macro1")

I get the notification in Workbook1 that Workbook2 is already open, prompting me to open as a read only or to notify.

 

I need to ensure that I target the instance of excel containing Workbook2 as the $oExcel object to call the run function.

I can find the PID based on title name, but am having trouble using the ObjGet( ) function to target a process by PID

Share this post


Link to post
Share on other sites
help_me_please

^^

Share this post


Link to post
Share on other sites
help_me_please

^^^

1 hour ago, Jimwright said:

I have 3 Excels open in taskmanager

 

3 hours ago, JLogan3o13 said:

@help_me_please how about showing us this code you're staring at, so we can see just what you're doing? Have you looked at the _Excel_* sections of the help file? You can easily open, create, or edit specific Workbooks with these functions.

 

Share this post


Link to post
Share on other sites
SmOke_N

Don't bump the thread again for another 24 hours or we'll lock it permanently.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
Jimwright

I still think you can use the built in excel functions to help you here.   I've got 2 spreadsheets - Workbook1.xlsm just has "hello" in A1.   ThisExcel.xlsm just has the Macro1 I mentioned earlier.   With no Excels currently running I run this:

#include <Excel.au3>
$oExcel=_excel_open()
;;Open the Input Workbook
$StrInputWB="C:\work\useful script\autoit\excelhelp\Workbook1.xlsm"
 $oInputWB=_Excel_BookOpen($oExcel, $StrInputWB)
 ;;Open the Output Workbook
$StrOutputWB="C:\work\useful script\autoit\excelhelp\ThisExcel.xlsm"
 $oOutputWB=_Excel_BookOpen($oExcel, $StrOutputWB)
;EG - activate input and do something
$oInputWB.activate
$ReadSomething=_Excel_RangeRead ($oInputWB,default,"A1")
consolewrite($ReadSomething) ;prove we read from input excel
;;activate output Excel
$oOutputWB.activate
$oExcel.run("Macro1") ;runs macro in the output book

Two Excels launch.   I then get "Hello" in the stdout stream to prove it read from input,  The macro then runs on the output Excel spreadsheet.

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  

×