Jump to content

Excel get Linksource


Fraser
 Share

Recommended Posts

Good Afternoon,

I'm trying to get the link source of a load of excel file and then change them to a new link, however for some reason when I use _excelbookopen to open the book I can't then use the returned object to get the link source ($aLinks = $oExcel.LinkSources($xlExcelLinks))

here is the code so far:

#include <array.au3>
#include <file.au3>
#include <excel.au3>

Dim $Filename
Dim $xlsApp
Dim $objWorkbook
Dim $i
Dim $newSheet
Dim $docs

$strFileNamelinkinfo = "C:\Users\User\desktop\output.csv"
$Filename = "C:\Users\User\desktop\file_names.txt"

ReadFile($Filename)

Func ReadFile($AFileName)
    _FileReadToArray($Filename, $docs)
    If IsArray($docs) Then
        _ArrayDisplay($docs)
        _ArrayDelete($docs, 0)
        For $file in $docs
        ListLinks($file)
        Next
    EndIf
EndFunc

Func ListLinks($strFileName)
    Dim $aLinks
    Const $xlExcelLinks = 1

    $oExcel = _ExcelBookOpen($strFileName)
    $oExcel = ObjGet("", "Excel.Application")
    msgbox(0, "", $oExcel)
    $aLinks = $oExcel.LinkSources($xlExcelLinks)
    _ExcelBookClose($oExcel, 0, 0)

    If IsArray($aLinks) Then
        msgbox(0, "", "Links returned")
    EndIf
Endfunc

Any suggestions?

Thanks
Jamie

Link to comment
Share on other sites

So you are using AutoIt 3.3.8.1 or older?

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

LinkSources is a method of the Workbook object, not the application object.

#include <array.au3>
#include <file.au3>
#include <excel.au3>
 
Dim $Filename
Dim $xlsApp
Dim $objWorkbook
Dim $i
Dim $newSheet
Dim $docs
 
$strFileNamelinkinfo = "C:\Users\User\desktop\output.csv"
$Filename = "C:\Users\User\desktop\file_names.txt"
 
ReadFile($Filename)
 
Func ReadFile($AFileName)
    _FileReadToArray($Filename, $docs)
    If IsArray($docs) Then
        _ArrayDisplay($docs)
        _ArrayDelete($docs, 0)
        For $file in $docs
        ListLinks($file)
        Next
    EndIf
EndFunc
 
Func ListLinks($strFileName)
    Dim $aLinks
    Const $xlExcelLinks = 1
 
    $oExcel = _ExcelBookOpen($strFileName) ; Returns the Excel application object
    $aLinks = $oExcel.ActiveWorkbook.LinkSources($xlExcelLinks)
    _ExcelBookClose($oExcel, 0, 0)
 
    If IsArray($aLinks) Then
        msgbox(0, "", "Links returned")
    EndIf
Endfunc

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

The Excel UDF in 3.3.8.1 will be very slow because you open and close Excel for every workbook.

When you upgrade to the latest Autoit version you will see a big performance gain because you open Excel once, process all workbooks and then close Excel again.

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,

Thanks for getting back to me.

I am running an older version of autoit (3.3.0) this is the only version that I can get approved at work at the moment, I have submitted a case to allow me to install the latest version however this can take a while.

That makes scene, works in a similar manner as VB where you specify the object and then the workbook, thank you for your help.

Regards,

Fraser

Edited by Fraser
Link to comment
Share on other sites

If speed is an issue then you could split the functions so that even with an older version of AutoIt and the Excel UDF it doesn't take ages to process all files.

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