Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
RAP RAP is offline
external usenet poster
 
Posts: 49
Default Filesearch .LookIn fixated on MyDocuments

Hello All,
Having made a habit of utilizing this newsgroup for "programming lessons",
and finding it invaluable, I finally have a question for which I cannot find
an answer. I think my answer is "find another way to do this without using
FileSearch." Yet, I must ask....
I am using typical FileSearch code (from this newsgroup) to locate the
latest file in a folder. In my application, this can be done via filenames
(mmyy at the beginning of each file in the folder). (Therein lies my answer)
The code worked a number of times with no problems, then starting giving the
following problem: The .LookIn value stays at "My Documents", (when moused
over while stepping through the code) instead of the coded folder on the
other side of the = sign. Anyone have any ideas on why this is happening?

With Application.FileSearch
.NewSearch
.LookIn = "C:\Some\Long\String\"
(mouse over .LookIn and get "C:\My Documents"

Looking forward to your experience and suggestions.
Randy
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Filesearch .LookIn fixated on MyDocuments

I don't know what the problem is with your FileSearch code.
However, FileSearch has a bad reputation and was removed from XL2007.
I prefer using the FileSystemObject - included in most versions of Windows.
(the Dir function also works)...
'---
Sub duce()
'Jim Cone - Portland, Oregon USA - June 2005
'Displays the latest file name in the strPath folder.

Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim strPath As String
Dim strName As String
Dim varDate As Date

' Specify the folder - Modify to suit...
strPath = "C:\Program Files\Microsoft Office\Office\Library"
' Use Microsoft Scripting runtime.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strPath)

' Check date on each file in folder.
For Each objFile In objFolder.Files
If objFile.DateLastModified varDate Then
varDate = objFile.DateLastModified
strName = objFile.Name
End If
Next 'objFile

' Display file name in message box.
MsgBox strName & " - is latest file - " & varDate

Set objFile = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
End Sub
'---
Jim Cone
Portland, Oregon USA




"RAP"
wrote in message
Hello All,
Having made a habit of utilizing this newsgroup for "programming lessons",
and finding it invaluable, I finally have a question for which I cannot find
an answer. I think my answer is "find another way to do this without using
FileSearch." Yet, I must ask....
I am using typical FileSearch code (from this newsgroup) to locate the
latest file in a folder. In my application, this can be done via filenames
(mmyy at the beginning of each file in the folder). (Therein lies my answer)
The code worked a number of times with no problems, then starting giving the
following problem: The .LookIn value stays at "My Documents", (when moused
over while stepping through the code) instead of the coded folder on the
other side of the = sign. Anyone have any ideas on why this is happening?

With Application.FileSearch
.NewSearch
.LookIn = "C:\Some\Long\String\"
(mouse over .LookIn and get "C:\My Documents"

Looking forward to your experience and suggestions.
Randy
  #3   Report Post  
Posted to microsoft.public.excel.programming
RAP RAP is offline
external usenet poster
 
Posts: 49
Default Filesearch .LookIn fixated on MyDocuments


  #4   Report Post  
Posted to microsoft.public.excel.programming
RAP RAP is offline
external usenet poster
 
Posts: 49
Default Filesearch .LookIn fixated on MyDocuments

Jim, Thank you for the promt reply. I simply pasted your code in a new
module, modified the strPath and ran the macro. Works perfectly. It now
looks like my new topic is: FileSystemObjects. Thanks again, Randy

"Jim Cone" wrote:

I don't know what the problem is with your FileSearch code.
However, FileSearch has a bad reputation and was removed from XL2007.
I prefer using the FileSystemObject - included in most versions of Windows.
(the Dir function also works)...
'---
Sub duce()
'Jim Cone - Portland, Oregon USA - June 2005
'Displays the latest file name in the strPath folder.

Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim strPath As String
Dim strName As String
Dim varDate As Date

' Specify the folder - Modify to suit...
strPath = "C:\Program Files\Microsoft Office\Office\Library"
' Use Microsoft Scripting runtime.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strPath)

' Check date on each file in folder.
For Each objFile In objFolder.Files
If objFile.DateLastModified varDate Then
varDate = objFile.DateLastModified
strName = objFile.Name
End If
Next 'objFile

' Display file name in message box.
MsgBox strName & " - is latest file - " & varDate

Set objFile = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
End Sub
'---
Jim Cone
Portland, Oregon USA




"RAP"
wrote in message
Hello All,
Having made a habit of utilizing this newsgroup for "programming lessons",
and finding it invaluable, I finally have a question for which I cannot find
an answer. I think my answer is "find another way to do this without using
FileSearch." Yet, I must ask....
I am using typical FileSearch code (from this newsgroup) to locate the
latest file in a folder. In my application, this can be done via filenames
(mmyy at the beginning of each file in the folder). (Therein lies my answer)
The code worked a number of times with no problems, then starting giving the
following problem: The .LookIn value stays at "My Documents", (when moused
over while stepping through the code) instead of the coded folder on the
other side of the = sign. Anyone have any ideas on why this is happening?

With Application.FileSearch
.NewSearch
.LookIn = "C:\Some\Long\String\"
(mouse over .LookIn and get "C:\My Documents"

Looking forward to your experience and suggestions.
Randy

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Filesearch .LookIn fixated on MyDocuments

You are welcome.
If interested, the help file for Windows Script (includes filesystemobject) was/is available here...
http://www.microsoft.com/downloads/d...DisplayLang=en
-or-
http://tinyurl.com/326arm
--
Jim Cone
Portland, Oregon USA


"RAP"
wrote in message
Jim, Thank you for the promt reply. I simply pasted your code in a new
module, modified the strPath and ran the macro. Works perfectly. It now
looks like my new topic is: FileSystemObjects. Thanks again, Randy



  #6   Report Post  
Posted to microsoft.public.excel.programming
RAP RAP is offline
external usenet poster
 
Posts: 49
Default Filesearch .LookIn fixated on MyDocuments

Jim, thanks for the link. It looks like it will keep me flush with reading
material for quite some time. Thanks again for the code. I'm off and
running again. - Randy

"Jim Cone" wrote:

You are welcome.
If interested, the help file for Windows Script (includes filesystemobject) was/is available here...
http://www.microsoft.com/downloads/d...DisplayLang=en
-or-
http://tinyurl.com/326arm
--
Jim Cone
Portland, Oregon USA


"RAP"
wrote in message
Jim, Thank you for the promt reply. I simply pasted your code in a new
module, modified the strPath and ran the macro. Works perfectly. It now
looks like my new topic is: FileSystemObjects. Thanks again, Randy


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
Do File Open and default to the MyDocuments dialog box Steven Excel Programming 4 March 19th 08 09:28 PM
Lookin property of the FileSearch object [email protected] New Users to Excel 0 December 5th 06 09:37 PM
Problem with setting a R / W property, FileSearch, LookIn chuckd Excel Programming 2 November 9th 06 03:31 PM
how can I display the file location (ie:C/mydocuments..)print medrvgc Excel Discussion (Misc queries) 2 May 20th 06 06:48 AM
Cannot assign value to Filesearch.Lookin QQExcel Excel Programming 3 August 5th 04 04:20 PM


All times are GMT +1. The time now is 12:15 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"