Club des développeurs Excel : cours, tutoriels, codes sources, livres, outils et forums dédiés à la programmation et à l'utilisation de Microsoft Excel

Bienvenue sur Excelabo.net
A VBA Function To Get A Value From A Closed File
Category: VBA Functions | [Item URL] VBA does not include a method to retrieve a value from a closed file. You can, however, take advantage of Excel's ability to work with linked files. This tip contains a VBA function that retrieves a value from a closed workbook. It does by calling an XLM macro. Note: You cannot use this function in a worksheet formula. The GetValue Function The GetValue function, listed below takes four arguments: path: The drive and path to the closed file (e.g., "d:\files") file: The workbook name (e.g., "budget.xls") sheet: The worksheet name (e.g., "Sheet1") ref: The cell reference (e.g., "C4") Private Function GetValue(path, file, sheet, ref) ' Retrieves a value from a closed workbook Dim arg As String ' Make sure the file exists If Right(path, 1) <> "\" Then path = path & "\" If Dir(path & file) = "" Then GetValue = "File Not Found" Exit Function End If ' Create the argument arg = "'" & path & "[" & file & "]" & sheet & "'!" Using the GetValue Function Caveat All Tips
Related:
Related: