Jump to content

_Excel_RangeCopyPaste not working with _ExcelBookOpen


Recommended Posts

Last year when I upgraded my AutoIT system (from vs 3.2.3 to vs 3.3.6.1) I was surprised to find that the IncludeFile "Excel.au3" had substantially changed. Many of the UDFs I had been using were gone and those that remained were renamed. For example    "_ExcelBookNew"  became  "_Excel_BookNew".

Another change was that the Constants were put in a separate Include file (ExcelConstants.au3).

Initially I did not have the time to change and test all my existing programs with the new UDFs. Therefore, as a short-term solution, I copied the old Excel.au3 file into another folder,  renamed it to  ExcelAU3_FromAI-vs323.au3, and referenced it (instead of Excel.au3) in the Include statements.

However going forward I would like to start using the new UDFs, as they contain a lot of nice features.

Today I started with the UDF _Excel_RangeCopyPaste (which did not exist in the old version). However I was disappointed to find that it did not work properly in my exisiting programs. Eventually, after a lot of experimentation, I discovered the problem. It's the way my programs open up Workbooks. They all use the UDF _ExcelBookOpen (from the old IncludeFile). However when I replaced  _ExcelBookOpen  with  _Excel_BookOpen (from the new IncludeFile) the programs worked fine.

TWO QUESTIONS:
(1) What is the reason for this?   Why does _Excel_RangeCopyPaste  behave differently depending on the way the workbook was opened???
(2) Are there other things I should be careful about with respect to the other new UDFs.

Now I am very concerned about implementing the new UDFs. If they would simply crash when the environment is not correct -- that would be ok. If I know there's a problem I can deal with it. However  _Excel_RangeCopyPaste did not crash. It just did not give the desired results in all cases. And usually these subtleties go unnoticed. To catch these problems would take a level of testing that I cannot afford right now.

Any suggestions would be greatly appreciated.

Link to comment
Share on other sites

POSTSCRIPT

I just looked inside the two BookOpen UDFs in question (old and new).
As I see it, here is the essential code..

;-----------------------------------
; UDF Old:   _ExcelBookOpen
;-----------------------------------
Func _ExcelBookOpen($sFilePath, $fVisible = 1, $fReadOnly = False, $sPassword = "", $sWritePassword = "")
$oExcel = ObjCreate("Excel.Application")
.WorkBooks.Open($sFilePath, Default, $fReadOnly, Default, $sPassword, $sWritePassword)

;-----------------------------------
UDF New:   _Excel_BookOpen
;-----------------------------------
Func _Excel_BookOpen($oExcel, $sFilePath, $bReadOnly = Default, $bVisible = Default, $sPassword = Default, $sWritePassword = Default)
$oWorkbook = $oExcel.Workbooks.Open($sFilePath, Default, $bReadOnly, Default, $sPassword, $sWritePassword)


It seems to me that the only difference is that the new UDF requires that Excel be opened by the calling program.

QUESTION:  Could this explain the behavior of _Excel_RangeCopyPaste ???

Edited by CE101
Link to comment
Share on other sites

11 hours ago, CE101 said:

Last year when I upgraded my AutoIT system (from vs 3.2.3 to vs 3.3.6.1) I was surprised to find that the IncludeFile "Excel.au3" had substantially changed.

I suggest to change to the actual stable 3.3.14.2 as the last script breaking change was in 3.3.14.0 and completly rewritten with 3.3.12.0. I think the support for the  actual version is better guaranted than for the outdated 3.3.6.1 version you have.

Link to comment
Share on other sites

Please check the docu for the change history. There is a link to script breaking changes. Another link leads you to the excel UDF. There you find what was changed and how to move to the new Excel UDF. 

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

Hi AutoBert and Water:

Thank you for responding.

AutoBert writes:
> I suggest to change to the actual stable 3.3.14.2
> as the last script breaking change was in 3.3.14.0
> and completly rewritten with 3.3.12.0.
> I think the support for the  actual version is better
> guaranted than for the outdated 3.3.6.1 version you have.

Actually I am running 3.3.12.0.  (I upgraded from 3.3.6.1).
However I have not yet gone all the way to 3.3.14.2.
(I have never been an early adopter).


As you suggested, I visited the log  https://www.autoitscript.com/autoit3/docs/history.htm
And I see the following entries (which are relevant to me):

 

VERSION 3.3.14.0 (10th July, 2015) (Release)

  • Changed: Minimum OS requirements are now Windows XP SP3 and Windows Server 2003 SP2.
  • Fixed #2993: _Excel_RangeFind returns only last occurrence of string found.
  • Changed: _Excel_BookOpen() changed from @error = 4 to @error = 0 and @extended = 1 if Workbook could not be opened Read-Write. This is a script breaking change.

VERSION 3.3.12.0 (1st June, 2014) (Release)

  • Changed: Excel UDF was re-written. Functions and/or parameters have been renamed, removed or added. This is a script breaking change.


Water writes:
> Another link leads you to the excel UDF.
> There you find what was changed and
> how to move to the new Excel UDF.  


QUESTIONS:
(1) I do not see a link to the UDF. Yes, I would be very interested in seeing the instructions on how to transition to the new Excel UDFs. What is the URL for that?
(2) What does it mean "script breaking change"?   What is so special about the changes that have this designation? Does it mean that a bug that was causing scripts to break was fixed? If so, does that mean that all the Excel UDFs prior to 3.3.12.0 had bugs of this type?

 

Link to comment
Share on other sites

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

:)

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...