Jump to content

[SOLVED] _Excel_BookOpen how to connect to already opened Excel Application, without knowing the filepath


Recommended Posts

Hello dear users!

I have a bit of a problem with my excel script I try to make. My goal is that my script would read through an excelfile's columns and rows, identifiying key words, then I would like to reorganize the rows and colums in the a specified "way", "format" (we get different kind of excels in and i wish to produce a uniform excels from them, the data is the same, so I know that there is an XY column somewhere, I just have to find it, and put it in the right place)

Now I can read values from cells (or range of cells) but only if I know the exact file name and path.

Can I make autoit to somehow attach to the already opened excel? This way I would be able to make the script, so the user just open the excel which he/she wants to format, clicks on go, and viola.

Instead now I'm thinking adding 2 textboxes to my GUI so the user can write down the filename and file path, which isnt that ideal.

My original idea, was to make the script find the "borders" of the filled out excel form, copy it away to the right, delete the original data, reorganize it the way it should be (to the area which it cleared), and thats it. The user can then quickly check if everything is okey, and he/she can delete the copied original data set if its needed.

 

So in short my problem is, how to connect my script to an excel thats presumaby already opened, without knowing the filename and path?

Thank you for your help! (and sorry if there is already a post about this I havent found it)

Edited by SorryButImaNewbie
SOLVED
Link to comment
Share on other sites

  • Moderators

You want to attach to an already open workbook, correct? The help file is your friend: Look at (funny enough) _Excel_BookAttach. You can attach to an open book based on filepath, filename, or title.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Use _Excel_BookList to retrieve an array of open workbooks. Then select the needed one and use _Excel_BookAttach to connect to this workbook.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Moderators

Once again, a trip through the help file would be beneficial. Look at _Excel_BookList.

Edit: D'oh, too slow

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Thanks!

First sorry for only replying now... This is a pet project of mine, and I didn't had time to check _Excel_BookList.

Sorry I know that everything is in the help files usually :D and if not 98% of the time it can be found on this very forum, I searched both, but I was unable to find what i was looking for. (thats my mistake, sorry)

I just started to play around with my code now, adding in the displayarray from the help file.

The array display shows me the running excel programs, but also shows me 3 additional things. I have a quess what are these, but I though I would ask, just to be sure.

2 XLAM file, from the library/analysis file, called  ATPVBAEN and FUNCRES. My guess is that these are something from the analysis toolpack, I'm not sure why they are here.

The 3. one is the SOLVER.XLAM. Thats the solver, I'm not sure why it is listed with the excel workbooks, but as long as it always the last member of the array (seems like it so far) its not a problem.

I thought that I should write a regex, that search for these, and remove them from the array before I start to do other operations.

(attached a JPG from a displayed array, 0. is an open excel, 1,2 are XLAM files, 3. an other opened excel, 4. is the solver)

Thank you, and sorry again for the slow reply

ArrayList.JPG

 

So I read the data from the array, I think I will use regex to find the .xls or .xlsm (excel) files, and make an error if there are more then one excel opened, asking the user, to open only one at a time.

If IsArray($aWorkBooks) Then
        Local $array0 = $aWorkBooks[0][1]
        MsgBox($MB_SYSTEMMODAL, "Excel", " Value of array0: " & $array0)
        Local $array1 = $aWorkBooks[1][1]
        MsgBox($MB_SYSTEMMODAL, "Excel", " Value of array1: " & $array1)
        Local $array2 = $aWorkBooks[2][1]
        MsgBox($MB_SYSTEMMODAL, "Excel", " Value of array2: " & $array2)
        Local $array3 = $aWorkBooks[3][1]
        MsgBox($MB_SYSTEMMODAL, "Excel", " Value of array3: " & $array3)

        Else
            Exit
    EndIf

 

Edited by SorryButImaNewbie
adding a bit of code, just for good measure
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

×
×
  • Create New...