I\'m having trouble putting the syntax together for this and I just started working with FSO in VBA, so please bear with me.
fsofol.name = test1 (this is correct)
Assuming that FSO is the Scripting.FileSystemObject
and that you want to work through all of the "V*.xls" files in a folder called "test1", you're missing a few steps:
Creating the file system object
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Assigning the folder
Dim fsoFol As Object
Set fsoFol = fso.GetFolder("C:\Temp\test1")
Working through the files
Dim fsoFile As Object
For Each fsoFile in fsoFol.Files
If fsoFile.Name Like "V*.xls" Then
' code for working with the Excel files goes here
End If
Next fsoFile
Open a specific Excel file and assign it to a variable
' Assuming you have Dim wbkCS As Workbook at the start of the module
Set wbkCS = Workbooks.Open(fsoFile.Name)
' code to process the actual file goes here
wbkCS.Close False
I'm unclear on what you are trying to do with the cells copied into wbkVer. You're copying nearly 2000 cells but only looking at the value of the first cell copied. Also the test Like "*"
will return True for both empty cells and cells with values so it probably isn't what you need. If you can clarify that requirement then we can move things on a bit
Change
fsoFol.Name.Copy **'error is here and states object required**
firstRange.Offset(0, 5).PasteSpecial xlPasteValues
to
firstRange.Offset(0, 5).Value = fsoFol.Name