All,
I have a large module which in the earlier part checks whether a files is in use (Readonly) format and if it is in use to open the next file. I.e. if file one is in use open file two etc..
In a later part of the module I wish to use the file which has been opened. However I am struggling to identify the file which is opened in the earlier part of the automation and set is as WB.
The code I am currently using is;
Dim wb As Object On Error Resume Next Workbooks("\\Csdatg04\psproject\Robot\Project Preload\Transactions\Transactions1.csv").Activate If Err.Number = 0 Then wb = GetObject("\\Csdatg04\psproject\Robot\Project Preload\Transactions\Transactions1.csv") GoTo skipline End If On Error GoTo 0 On Error Resume Next Workbooks("\\Csdatg04\psproject\Robot\Project Preload\Transactions\Transactions2.csv").Activate If Err.Number = 0 Then wb = GetObject("\\Csdatg04\psproject\Robot\Project Preload\Transactions\Transactions2.csv") GoTo skipline End If On Error GoTo 0 On Error Resume Next Workbooks("\\Csdatg04\psproject\Robot\Project Preload\Transactions\Transactions3.csv").Activate If Err.Number = 0 Then wb = GetObject("\\Csdatg04\psproject\Robot\Project Preload\Transactions\Transactions3.csv") GoTo skipline End If On Error GoTo 0 On Error Resume Next Workbooks("\\Csdatg04\psproject\Robot\Project Preload\Transactions\Transactions4.csv").Activate If Err.Number = 0 Then wb = GetObject("\\Csdatg04\psproject\Robot\Project Preload\Transactions\Transactions4.csv") GoTo skipline End If skipline: On Error GoTo 0 Can anyone recommend how I can identify which file is open and set is as WB
Any help would be much appreciated.
Thanks
wbit's not clear why you're "struggling to identify the file"?wbcan point to only one file. But I believe part of your problem is that you never turn the error handling back on, so you're not seeing error messages that could help you. I believe you need toSet wb =...to get the workbook object the code addresses withGet Object. That would be a start, anyway.