I have several thousand files I want to work on. Each file takes a few minutes of processing so to speed up the process I'm trying to use several computers that all dump their processed files to a central location. What I've noticed is that the different computers end up trying to open files for processing that are in the process of processing. To solve this problem I'm experimenting with using a dummy text file as a sort of
It works for the most part... Once in a while when I go to save the process xlsx file I get a popup explorer window with an alternative file name:
Copy of XYZ.xlsx instead of XYZ.xlsx
I'm not sure what the problem is here but I suspect it's two computers trying to process the same file - i.e. somehow the dummy txt file blocking mechanism didn't work. Can anyone suggest a remedy and/or an alternative way to create a GATE that prevents multiple computers from working on the same file?
It works for the most part... Once in a while when I go to save the process xlsx file I get a popup explorer window with an alternative file name:
Copy of XYZ.xlsx instead of XYZ.xlsx
I'm not sure what the problem is here but I suspect it's two computers trying to process the same file - i.e. somehow the dummy txt file blocking mechanism didn't work. Can anyone suggest a remedy and/or an alternative way to create a GATE that prevents multiple computers from working on the same file?
Code:
Do
Flag = True
For k = 2 To j
Latitude = Operating_Units(k, 14)
Longitude = Operating_Units(k, 15)
'Check if file has already been processed.
If Dir(Folder_XLS & Latitude & "_" & Longitude & ".txt") = "" Then
'Save dummy txt file
Set fso = CreateObject("Scripting.FileSystemObject")
Set oFile = fso.CreateTextFile(Folder_XLS & Latitude & "_" & Longitude & ".txt")
oFile.Close
Set fso = Nothing
Set oFile = Nothing
Flag = False
Exit For
End If
Next k
If Flag = True Then
'All files have been processed
Exit Do
End If
File_x = Latitude & "_" & Longitude & ".xlsx"
'Open Weather File
If Dir(Folder_XLS & File_x) = "" Then
Stop
Else
Workbooks.Open Folder_XLS & File_x
End If
Data = Sheets("Sheet1").Range("A1:P210385")
For k = 2 To 210383
Year = Left(Dates(k, 1), 4)
Month = Right(Left(Dates(k, 1), 7), 2)
Day = Right(Left(Dates(k, 1), 10), 2)
Hour = Right(Left(Dates(k, 1), 17), 2)
Azimuth = solarazimuth(Latitude, Longitude, Year, Month, Day, Hour, 0, 0, -8, 0)
Elevation = solarelevation(Latitude, Longitude, Year, Month, Day, Hour, 0, 0, -8, 0)
Data(k + 2, 15) = Round(Elevation, 3)
Data(k + 2, 16) = Round(Azimuth, 3)
Next k
Data(1, 15) = "Elevation"
Data(1, 16) = "Azimuth"
Sheets("sheet1").Range("A1:P210385") = Data
'Here's the step that's hanging up.
Call Save_File(File_x, Folder_XLS)
Loop
Function Save_File(File_x As String, Folder_XLS As String)
Application.EnableEvents = False
Application.DisplayAlerts = False
Workbooks(File_x).Close SaveChanges:=True
Application.EnableEvents = True
Application.DisplayAlerts = True
End Function
Last edited: