Page 1 sur 1
[Func] Ouvrir un fichier Excel sans mettre à jour liaisons
Posté : ven. 28 févr. 2014 15:55
par ltrautoit
Bonjour,
Pour mon usage personnel, je souhaite accéder à un fichier excel via des macros (donc automatiquement sans intervention humaine)
Sauf que je n'ai pas le contrôle du fichier auquel je souhaite accéder et qu'il comporte des liaisons, ce qui bloque l'accès automatique (invite de mise à jour des liaisons)
J'ai donc légèrement modifié la fonction _ExcelBookOpen vers _ExcelBookOpenUpdate en ajoutant un paramètre inhibant les questions relatives à la mise à jour des liaisons.
► Afficher le texte
Code : Tout sélectionner
; #FUNCTION# ====================================================================================================================
; Name...........: _ExcelBookOpenUpdate
; Description ...: Opens an existing workbook and returns its object identifier.
; Syntax.........: $oExcel = _ExcelBookOpen($sFilePath, $fVisible = 1, $fReadOnly = False, $sPassword = "", $sWritePassword = "")
; Parameters ....: $sFilePath - Path and filename of the file to be opened
; $fVisible - Flag, whether to show or hide the workbook (0=not visible, 1=visible) (default=1)
; $fReadOnly - Flag, whether to open the workbook as read-only (True or False) (default=False)
; $sPassword - The password that was used to read-protect the workbook, if any (default is none)
; $sWritePassword - The password that was used to write-protect the workbook, if any (default is none)
; $fUpdatelinks - Flag, whether to update or not the links (0=not update, 1=update) (default= Ask the User)
; Return values .: Success - Returns new object identifier
; Failure - Returns 0 and sets @error on errors:
; @error=1 - Unable to create the object
; @error=2 - File does not exist
; Author ........: SEO <locodarwin at yahoo dot com>
; Modified.......:
; Remarks .......: None
; Related .......:
; Link ..........;
; Example .......; Yes
; ===============================================================================================================================
Func _ExcelBookOpenUpdate($sFilePath, $fVisible = 1, $fUpdatelinks = 0, $fReadOnly = False, $sPassword = "", $sWritePassword = "")
Local $oExcel = ObjCreate("Excel.Application")
If Not IsObj($oExcel) Then Return SetError(1, 0, 0)
If Not FileExists($sFilePath) Then Return SetError(2, 0, 0)
If $fVisible > 1 Then $fVisible = 1
If $fVisible < 0 Then $fVisible = 0
If $fReadOnly > 1 Then $fReadOnly = 1
If $fReadOnly < 0 Then $fReadOnly = 0
With $oExcel
.Visible = $fVisible
If $sPassword <> "" And $sWritePassword <> "" Then .WorkBooks.Open($sFilePath, $fUpdatelinks, $fReadOnly, Default, $sPassword, $sWritePassword)
If $sPassword = "" And $sWritePassword <> "" Then .WorkBooks.Open($sFilePath, $fUpdatelinks, $fReadOnly, Default, Default, $sWritePassword)
If $sPassword <> "" And $sWritePassword = "" Then .WorkBooks.Open($sFilePath, $fUpdatelinks, $fReadOnly, Default, $sPassword, Default)
If $sPassword = "" And $sWritePassword = "" Then .WorkBooks.Open($sFilePath, $fUpdatelinks, $fReadOnly)
.ActiveWorkbook.Sheets(1).Select ()
EndWith
Return $oExcel
EndFunc ;==>_ExcelBookOpenUpdate
Hope it helps, comme on dit !