ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   GetOpenFilename (https://www.excelbanter.com/excel-programming/298529-getopenfilename.html)

Chodu

GetOpenFilename
 
I want the user to open multiple Excel files at once (if
possible, all files in a specific directory.

Since my code is in access, I'm using the following method:
Excel.Application.GetOpenFilename("XLS (*.xls),
*.xls", , "Open All Files Here", , True)

I know that since multiple select is true, this code will
return an array with all of the file names. I just don't
know how to assign a reference to this array so that I can
open all of the workbooks.

TIA
Chodu

Rob Bovey

GetOpenFilename
 
Hi Chodu,

Here's an example of one way to make this work.

Sub OpenMultipleFiles()
Dim vaFileNames As Variant
Dim vItem As Variant
vaFileNames = Excel.Application.GetOpenFilename( _
"XLS (*.xls), *.xls", , "Open All Files Here", , True)
' If the result is not an array the user cancelled
' the dialog.
If IsArray(vaFileNames) Then
For Each vItem In vaFileNames
Excel.Application.Workbooks.Open vItem
Next vItem
End If
End Sub

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


"Chodu" wrote in message
...
I want the user to open multiple Excel files at once (if
possible, all files in a specific directory.

Since my code is in access, I'm using the following method:
Excel.Application.GetOpenFilename("XLS (*.xls),
*.xls", , "Open All Files Here", , True)

I know that since multiple select is true, this code will
return an array with all of the file names. I just don't
know how to assign a reference to this array so that I can
open all of the workbooks.

TIA
Chodu





All times are GMT +1. The time now is 09:04 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com