Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello everybody! I have this macro in VB, but I want open all workbooks that are in this folder, but I dont know how will be the names of all workbooks. I tried this but it doesn't work..
FUNCTION ConvertirFormatoArchivos()
Dim file, origen
Set objExcel = CreateObject("Excel.Application")
set file = CreateObject("Scripting.FileSystemObject")
CurrentDirectory = path.GetAbsolutePathName(".")
origen = CurrentDirectory & "\Bajadas\"
file = origen & "*.xlsb"
While (file <> "")
objExcel.Workbooks.Open(file)
file = origen & "*.xlsb" 'Tomo todos los archivos binarios de la carpeta \Bajadas
Wend
END FUNCTION
Thank you!!
This works in the edit module
sub Loopfiles
Dim file, origen
Set objExcel = CreateObject("Excel.Application")
set objFileSys = CreateObject("Scripting.FileSystemObject")
origen = "mypath\"
set filelist = objFileSys.GetFolder(origen)
for each file in filelist.files
msgbox(file)
next
end sub
Try using the DIR function instead.
Regards.
I had tried before with Dir() but it show this error: "Type mismatch: 'Dir' "
Here is a little example, replace 'mypath' with your own folder...
Sub LoopThroughFiles()
Dim StrFile As String
StrFile = Dir("mypath\*.docx")
Do While Len(StrFile) > 0
Debug.Print StrFile
StrFile = Dir
Loop
End Sub
Show the same error: "Type mismatch: 'DIR' ".
I done this macro In Tools -> Edit module, not in the load script.
Strange,
I tested it using Excel VBA, I'll try it in a QV module and let you know.
ML.
OK, Thank you!!
Seems that the edit module does not support the required Type. I can't find any way to "dim as".
If it is any consolation, the follow works in the script:?
Sub LoopThroughFiles
Let FileMask= mypath & '\*.csv';
FOR Each File in filelist (FileMask)
TRACE(File);
Next
End Sub
Call LoopThroughFiles
Marty.
This works in the edit module
sub Loopfiles
Dim file, origen
Set objExcel = CreateObject("Excel.Application")
set objFileSys = CreateObject("Scripting.FileSystemObject")
origen = "mypath\"
set filelist = objFileSys.GetFolder(origen)
for each file in filelist.files
msgbox(file)
next
end sub
sub fileopen()
mypath = "Your Path"
fname = Dir(mypath & "*.xlsb")
Do While Len(fname) > 0
Workbooks.Open Filename:=mypath & fname
--your other coding what you want with file-----
fname = Dir
Loop
End Sub