Hey,
I have another issue that I'm hoping someone here can solve without too much effort. I had an earlier problem where I needed to move sheets from a workbook with the naming convention of "DDMMYY.xls" I solved that problem thanks to shg with the following code:
The issue I need help with is if the sheet has been opened multiple times, the naming convention of the file is changed to "DDMMYY(n).xls" Note the integer 'n' - I would like to somehow account for that.![]()
Sub Date2() Dim wkb As Workbook Set wkb = MostRecentWkb(10) If wkb Is Nothing Then MsgBox "The macro is not finding a Failed Trade Report open." Else wkb.Activate End If End Sub Function MostRecentWkb(Optional nDays As Long = 1) As Workbook Dim iDays As Long Dim sWkb As String For iDays = 0 To Abs(nDays) sWkb = WorksheetFunction.Text(Date - iDays, "mmddyy") & ".xls" If WorkbookIsOpen(sWkb) Then Set MostRecentWkb = Workbooks(sWkb) Exit For End If Next iDays End Function Function WorkbookIsOpen(sWkb As String) As Boolean On Error Resume Next WorkbookIsOpen = Not Workbooks(sWkb) Is Nothing Err.Clear End Function
So, a file typically named "050509.xls" opens fine and works in my macro perfectly, but if a file is named "050509(2).xls" or "050509(6).xls", the macro is not locating the file. Does anyone know any quick fixes to my issue? It is not a huge deal, if no answer is found, I can provide a disclaimer to users explaining the problem.
Bookmarks