Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I am new to VBA.
I wanted to have a macro open a last modified workbook in the folder. I saw the one code in the discussion group, his did not work so i changed it little bit. here's my code: Sub OpenMost() Dim strFolderName As String strFolderName = "D:\My Documents" On Error GoTo Err_Handler Dim strFileName With Application.FileSearch .LookIn = strFolderName .FileType = msoFileTypeExcelWorkbooks .SearchSubFolders = True If .Execute(msoSortByLastModified, msoSortOrderDescending) 0 Then strFileName = .FoundFiles(1) Application.Workbooks.Open strFileName End If End With Exit_Sub: Exit Sub Err_Handler: Resume Exit_Sub End Sub instead of opening the last modified file, it is sorting by the file name and opening the first one. what is wrong with this code? Thank You |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
A known bug I believe. A separate priming call seems to sort it, it did for
me Sub OpenMost() Dim strFolderName As String strFolderName = "D:\My Documents" On Error GoTo Err_Handler Dim strFileName With Application.FileSearch .NewSearch .LookIn = strFolderName .FileType = msoFileTypeExcelWorkbooks .SearchSubFolders = True .Execute SortBy:=msoSortBySize .LookIn = strFolderName .FileType = msoFileTypeExcelWorkbooks .SearchSubFolders = True If .Execute(msoSortByLastModified, msoSortOrderDescending) 0 Then strFileName = .FoundFiles(1) Application.Workbooks.Open strFileName End If End With Exit_Sub: Exit Sub Err_Handler: Resume Exit_Sub End Sub -- HTH RP (remove nothere from the email address if mailing direct) "GEORGIA" wrote in message ... I am new to VBA. I wanted to have a macro open a last modified workbook in the folder. I saw the one code in the discussion group, his did not work so i changed it little bit. here's my code: Sub OpenMost() Dim strFolderName As String strFolderName = "D:\My Documents" On Error GoTo Err_Handler Dim strFileName With Application.FileSearch .LookIn = strFolderName .FileType = msoFileTypeExcelWorkbooks .SearchSubFolders = True If .Execute(msoSortByLastModified, msoSortOrderDescending) 0 Then strFileName = .FoundFiles(1) Application.Workbooks.Open strFileName End If End With Exit_Sub: Exit Sub Err_Handler: Resume Exit_Sub End Sub instead of opening the last modified file, it is sorting by the file name and opening the first one. what is wrong with this code? Thank You |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
any ideas how to fix this "bug" or whatever it is ?
thank you "Bob Phillips" wrote: A known bug I believe. A separate priming call seems to sort it, it did for me Sub OpenMost() Dim strFolderName As String strFolderName = "D:\My Documents" On Error GoTo Err_Handler Dim strFileName With Application.FileSearch .NewSearch .LookIn = strFolderName .FileType = msoFileTypeExcelWorkbooks .SearchSubFolders = True .Execute SortBy:=msoSortBySize .LookIn = strFolderName .FileType = msoFileTypeExcelWorkbooks .SearchSubFolders = True If .Execute(msoSortByLastModified, msoSortOrderDescending) 0 Then strFileName = .FoundFiles(1) Application.Workbooks.Open strFileName End If End With Exit_Sub: Exit Sub Err_Handler: Resume Exit_Sub End Sub -- HTH RP (remove nothere from the email address if mailing direct) "GEORGIA" wrote in message ... I am new to VBA. I wanted to have a macro open a last modified workbook in the folder. I saw the one code in the discussion group, his did not work so i changed it little bit. here's my code: Sub OpenMost() Dim strFolderName As String strFolderName = "D:\My Documents" On Error GoTo Err_Handler Dim strFileName With Application.FileSearch .LookIn = strFolderName .FileType = msoFileTypeExcelWorkbooks .SearchSubFolders = True If .Execute(msoSortByLastModified, msoSortOrderDescending) 0 Then strFileName = .FoundFiles(1) Application.Workbooks.Open strFileName End If End With Exit_Sub: Exit Sub Err_Handler: Resume Exit_Sub End Sub instead of opening the last modified file, it is sorting by the file name and opening the first one. what is wrong with this code? Thank You |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I gave you the code to get around it.
-- HTH RP (remove nothere from the email address if mailing direct) "GEORGIA" wrote in message ... any ideas how to fix this "bug" or whatever it is ? thank you "Bob Phillips" wrote: A known bug I believe. A separate priming call seems to sort it, it did for me Sub OpenMost() Dim strFolderName As String strFolderName = "D:\My Documents" On Error GoTo Err_Handler Dim strFileName With Application.FileSearch .NewSearch .LookIn = strFolderName .FileType = msoFileTypeExcelWorkbooks .SearchSubFolders = True .Execute SortBy:=msoSortBySize .LookIn = strFolderName .FileType = msoFileTypeExcelWorkbooks .SearchSubFolders = True If .Execute(msoSortByLastModified, msoSortOrderDescending) 0 Then strFileName = .FoundFiles(1) Application.Workbooks.Open strFileName End If End With Exit_Sub: Exit Sub Err_Handler: Resume Exit_Sub End Sub -- HTH RP (remove nothere from the email address if mailing direct) "GEORGIA" wrote in message ... I am new to VBA. I wanted to have a macro open a last modified workbook in the folder. I saw the one code in the discussion group, his did not work so i changed it little bit. here's my code: Sub OpenMost() Dim strFolderName As String strFolderName = "D:\My Documents" On Error GoTo Err_Handler Dim strFileName With Application.FileSearch .LookIn = strFolderName .FileType = msoFileTypeExcelWorkbooks .SearchSubFolders = True If .Execute(msoSortByLastModified, msoSortOrderDescending) 0 Then strFileName = .FoundFiles(1) Application.Workbooks.Open strFileName End If End With Exit_Sub: Exit Sub Err_Handler: Resume Exit_Sub End Sub instead of opening the last modified file, it is sorting by the file name and opening the first one. what is wrong with this code? Thank You |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
duh! sorry!
THANK A BUNCH! IT WORKS PERFECTLY! "Bob Phillips" wrote: I gave you the code to get around it. -- HTH RP (remove nothere from the email address if mailing direct) "GEORGIA" wrote in message ... any ideas how to fix this "bug" or whatever it is ? thank you "Bob Phillips" wrote: A known bug I believe. A separate priming call seems to sort it, it did for me Sub OpenMost() Dim strFolderName As String strFolderName = "D:\My Documents" On Error GoTo Err_Handler Dim strFileName With Application.FileSearch .NewSearch .LookIn = strFolderName .FileType = msoFileTypeExcelWorkbooks .SearchSubFolders = True .Execute SortBy:=msoSortBySize .LookIn = strFolderName .FileType = msoFileTypeExcelWorkbooks .SearchSubFolders = True If .Execute(msoSortByLastModified, msoSortOrderDescending) 0 Then strFileName = .FoundFiles(1) Application.Workbooks.Open strFileName End If End With Exit_Sub: Exit Sub Err_Handler: Resume Exit_Sub End Sub -- HTH RP (remove nothere from the email address if mailing direct) "GEORGIA" wrote in message ... I am new to VBA. I wanted to have a macro open a last modified workbook in the folder. I saw the one code in the discussion group, his did not work so i changed it little bit. here's my code: Sub OpenMost() Dim strFolderName As String strFolderName = "D:\My Documents" On Error GoTo Err_Handler Dim strFileName With Application.FileSearch .LookIn = strFolderName .FileType = msoFileTypeExcelWorkbooks .SearchSubFolders = True If .Execute(msoSortByLastModified, msoSortOrderDescending) 0 Then strFileName = .FoundFiles(1) Application.Workbooks.Open strFileName End If End With Exit_Sub: Exit Sub Err_Handler: Resume Exit_Sub End Sub instead of opening the last modified file, it is sorting by the file name and opening the first one. what is wrong with this code? Thank You |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Open Last Modified File form Location | Excel Discussion (Misc queries) | |||
modified amortization schedule for open ended loan with EOM LPP ch | Excel Discussion (Misc queries) | |||
Excel File Open Box - want Date Modified | Excel Discussion (Misc queries) | |||
modified time of a worksheet | Excel Programming | |||
Copy Modified Worksheet 1 Data to Worksheet 2 | Excel Programming |