Jump to content

[solved] Object type returned by Excel UDF + Thiswookbook trap


Myicq
 Share

Recommended Posts

I am developing some excel export code.

A small part is outputting some constants not in the excel UDF.

I can find the constant using VBA editor from Excel. But my question is basically (since it did not work in AutoIT):

In terms of VBA code, which object type is $oExcel in this code:

Local $oExcel = _ExcelBookOpen(@ScriptDir & "\" & "tstfile.xlsx", 1)

I tried to do this:

; VBA CODE which works
Sub s()
MsgBox Application.ThisWorkbook.FullName
End Sub

personally I think $oExcel is an application object, so this should work:

ConsoleWrite("From Excel file : " & $oExcel.ThisWorkbook.FullName & @CRLF)

.. but it does not.

What am I missing here ? Normally I know my way in and out of VBA etc.

Edited by Myicq

I am just a hobby programmer, and nothing great to publish right now.

Link to comment
Share on other sites

Update:

This is a real trap.

ThisWorkbook is for the workbook where the macro code is running. Since AutoIT is technically not running inside a workbook, it fails.

ActiveWorkbook the the visible workbook.

So, changing code to

"From Excel file : " & $oExcel.ActiveWorkbook.FullName & @CRLF

Will leave thread for others to learn.

And found that $oExcel IS an Application object, in VBA sense.

I am just a hobby programmer, and nothing great to publish right now.

Link to comment
Share on other sites

Correct. The object returned by _ExcelBookOpen is an application object.

Try

$oExcel.ActiveWorkbook.FullName
to get the full name of the workbook.

BTW: I'm just about to completely rewrite the that comes with AutoIt. The new UDF will get rid of all limitations the current version has.

In your case you will get the object of the opened workbook not the application.

Please have a look and tell me what you think.

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

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...