Sign in to follow this  
Followers 0
Fraser

Excel get Linksource

6 posts in this topic

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

Share this post


Link to post
Share on other sites



So you are using AutoIt 3.3.8.1 or older?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0