Re: FileSystemObject Issues



On May 28, 11:40 pm, bgetson <bget...@xxxxxxxxx> wrote:
I'm getting an "invalid procedure call or argument" every time I try
to take control of a collection of files that I've grabbed. With this
setup:

Dim wkbk1 As Workbook, wkbk2 As Workbook
Dim objFSO As FileSystemObject
Dim objFiles As Files

Set objFSO = New FileSystemObject
Set objFiles = objFSO.GetFolder(strFolder).Files 'strFolder is some
path
Set wkbk1 = Workbooks.Open(objFiles(1))
Set wkbk2 = Workbooks.Open(objFiles(2))

I get an error the moment objFiles(1) or objFiles.Item(1) is called. I
know there are two files in the proper folder. objFiles.Count returns
2.

For Each f in objFiles
Workbooks.Open(f)
Next

^ This properly opens both files as I thought my original call should
have. What am I doing wrong?

On a side note, what is the proper way to open up a number of files in
a specific directory and assign each of them to a variable, so that I
can mess with them all simultaneously? In this case, I just happened
to know there were only two files, and I thought this would be
easiest.

Thanks for the help.

Hello bgetson,

I assume you have set a reference in your VBA project to the Windows
Script Host Object module, since you are using early binding. Instead
of dimensioning objFiles As Files, change it to a generic object: Dim
objFiles As Object. The Workbook.Open requires the file name string to
be fully qualified if it is in a different directory than the current
one. Use the Path property for this.

Dim wkbk1 As Workbook, wkbk2 As Workbook
Dim objFSO As FileSystemObject
Dim objFiles As Object

Set objFSO = New FileSystemObject
Set objFiles = objFSO.GetFolder(strFolder).Files 'strFolder is some
path
Set wkbk1 = Workbooks.Open(objFiles(1).Path)
Set wkbk2 = Workbooks.Open(objFiles(2).Path)

Sincerely,
Leith Ross
.



Relevant Pages

  • Re: owner propety on files
    ... I'm guessing the script would fire on ... Dim i, sHeadings ... Dim objExcel, objWorkbook, objWorksheet ... Dim objFolder, objFiles, objFile, objSubFolder ...
    (microsoft.public.scripting.vbscript)
  • Re: Verzeichnisstruktur auslesen
    ... Ich würde das FileSystemObject nehmen, ... Dim Unterverzeichnis As Folder ... ' Schreibe alle Dateinamen der Unterverzeichnisse vom Pfad ... Starte einfach die Prozedur test, diese erstellt mit Hilfe der Prozedur ...
    (microsoft.public.de.excel)
  • Re: owner propety on files
    ... Below i pasted both the script that pulls owner property and my existing ... Dim arrHeaders ... Dim objExcel, objWorkbook, objWorksheet ... Dim objFso, objFolder, objFiles, objFile ...
    (microsoft.public.scripting.vbscript)
  • Re: owner propety on files
    ... I find also show the constant as 8 for owner. ... Dim i, sHeadings ... Dim objExcel, objWorkbook, objWorksheet ... Dim objFolder, objFiles, objFile, objSubFolder ...
    (microsoft.public.scripting.vbscript)
  • Re: Massive speed difference between identical asp pages
    ... >> filesystemobject and writes an activeX component called iDrop for each ... So it's the FileSystemObject that's got the problem. ... dim thisFolder, subFolder, file ... set thisfolder = fso.GetFolder ...
    (microsoft.public.inetserver.asp.general)