I'm currently coding a small VBA tool in order to quickly sort files according to some data inside. As an example, I have a "To be sorted" folder with some files in it, lets say "File1.xls, File2.xls" and so on.
To read data in "FileX.xls", I use ExecuteExcel4Macro
(with the range and filename set properly), then I can use this data to apply filters and move files in other directories.
My code works fine with local files, but when I try to run it on my server (the tool aims at sorting files stored on the server), a dialog box "Update values" appears when I use ExecuteExcel4Macro
.
From here, I have to options:
Here is the portion of code that bothers me
For Each fsoFile In fsoParentFol.Files
'I only want to sort .xls files
If Right(fsoFile.Name, 4) = ".xls" Then
'On active le workbook actuel
strRef = "'[" & fsoFile.Name & "]" & "Sheet1" & "'!"
'this is the data I want to retrieve ... and this is where the dialog pops up
projectName = ExecuteExcel4Macro(strRef & rngProjectName.Address(1, 1, xlR1C1))
'some more code goes here but is irrelevant
End If
Next fsoFile
So my question is: how can I disable this dialog or, if it's a bad idea, are there other clean methods (I don't want to open each workbook, even with screenupdate turned off) that could solve my issue?
DisplayAlerts = False
doesn't solve the problem. And again, the program runs fine without this dialog.
I've of course tried to research online my problem first before posting here, but even subjects like this one aren't solutions to my problem.
Change the UNC path to a path using the drive letter that the server is mapped to:
So for example, change your string to produce:
[P:\Some_Folder\myfile.xls]Sheet1!A1
Instead of:
[\\my-server\Some_Folder\myfile.xls]Sheet1!A1
You could try using the replace function to achieve this:
strRef = "'[" & Replace(fsoFile.Name, "\\", "P:\") & "]" & "Sheet1" & "'!"