Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default open last modified worksheet

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default open last modified worksheet

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default open last modified worksheet

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default open last modified worksheet

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default open last modified worksheet

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Open Last Modified File form Location Kam Excel Discussion (Misc queries) 4 December 30th 09 05:47 PM
modified amortization schedule for open ended loan with EOM LPP ch staplers Excel Discussion (Misc queries) 7 June 28th 09 03:12 PM
Excel File Open Box - want Date Modified Titian Excel Discussion (Misc queries) 2 February 26th 06 08:25 AM
modified time of a worksheet Gary Adamson[_2_] Excel Programming 1 August 26th 04 10:42 PM
Copy Modified Worksheet 1 Data to Worksheet 2 clarkelrc Excel Programming 0 April 15th 04 01:36 PM


All times are GMT +1. The time now is 10:58 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"