cancel
Showing results for 
Search instead for 
Did you mean: 

Error while trying to attach an Excel spreadsheet by _Excel_BookAttach () function AutoIt

0 Kudos

Hello community!

Error while trying to attach an Excel spreadsheet by _Excel_BookAttach () function AutoIt the sheet was opened by an SAP transaction, so I'm using only the _Excel_Open () function but this returning an intermittent error in my script, does anyone can me help out?

Global $aWins = WinList ($sSAP_Excel_Temp)
_ArrayDisplay ($aWins)
$oWorkBook = _Excel_BookAttach ($aWins[1] [0], "Title")
Error = "1 - An error occurred or $ sString can not be found in any of the open workbooks @extended is Set to the COM error code."
@Error = 1 @ extended = -2147352570

I believe I'm using the same resource mentioned in this link:
http://help.sap.com/saphelp_afs64/helpdata/ja/e3/41a138c4397a42e10000009b38f842/content.htm


Thank you so much!

Márcio.

Accepted Solutions (0)

Answers (2)

Answers (2)

0 Kudos

Hello Stefan,

I found an article that explains exactly where I'm stuck!

http://help.sap.com/saphelp_afs64/helpdata/ja/b7/989d37d373243de10000009b38f8cf/content.htm


After clicking the "Export List Object to XXL" I choose the option: Table, automatically opens a excel window with the SAP data, but I can not access with _Excel_BookAttach () not even get the name using the function _excel_BookList ()

* My main goal is to copy the data from the Excel window and paste it into MS Word and then format and print.

You have any other alternative? I believe not be possible to attach the spreadsheet with _Excel_BookAttach () function.

Once again thank you for your attention ever.


Márcio.

holger_khn
Contributor
0 Kudos

If you have an ALV List als Source just Reader Data from there into an Excel Worksheet.

0 Kudos

Hello Holger Kohn,

It is exactly what I'm trying to do through the AutoIt, but not yet succeeded.

You would have to help me.

Thank you very much!

Marcio.

holger_khn
Contributor
0 Kudos

How to read ALV and cremte an CSV file is good explaniert by Stefan Schnell in this document:

YOu just need to use this technic and convert into AutoIT Syntax.

0 Kudos

Hello Holger Kohn,

I believe to be able to convert the code to AutoIt. If I can not access the instance of Excel will try to save CSV file.

Thank you so much.

Márcio.

stefan_schnell
Active Contributor
0 Kudos

Hello Marcio,

try this to attach to an open Excel workbook:

;-Begin-----------------------------------------------------------------

  ;-Includes------------------------------------------------------------

    #include "Array.au3"

    #include "Excel.au3"

  ;-Main----------------------------------------------------------------

    $aWorkBooks = _Excel_BookList()

    ;_ArrayDisplay($aWorkBooks)

    For $i = 0 To UBound($aWorkBooks) - 1

      If StringInStr(String($aWorkBooks[$i][1]), "Mappe1") Then

        $oWorkBook = _Excel_BookAttach($aWorkBooks[$i][2] + "\" + _

          $aWorkBooks[$i][1])

      EndIf

    Next

;-End-------------------------------------------------------------------

With _Excel_BookList you get all open workbooks. Loop over all open workbooks and find the right workbook based on a substring of the title. Attach to this workbook via path and name of the workbook.

Let us know your results.

Cheers

Stefan

0 Kudos

Hello Stefan,

The _Excel_BookList () function did not find any open workbook.

... Until we solve this issue, it would be possible to copy the data to clipboard through AutoIt?

Thank you.

Márcio.

stefan_schnell
Active Contributor
0 Kudos

Hello Marcio,

please have a closer look to the _Excel_BookList function of AutoIt. It scans the class ID {00020819-0000-0000-C000-000000000046} = Microsoft.Office.Interop.Excel.WorkbookClass. If you open an Excel instance you should find an open workbook. It is weired that you can't find any open workbook.

Let us know your results.

Cheers

Stefan

0 Kudos

Hello Stefan,

The _Excel_BookList () function does not find an open instance of the SAP GUI.
I found an Excel process in the task manager, but _Excel_BookList () function found nothing.

Like I already said before ...

...I found an article that explains exactly where I'm stuck!

http://help.sap.com/saphelp_afs64/helpdata/ja/b7/989d37d373243de10000009b38f8cf/content.htm

Muito obrigado!

Márcio.