Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 23rd, 2005, 01:59 PM
Authorized User
 
Join Date: Feb 2005
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default FileSearch method fails

Hi everyone,

I have a nice programme which searches for some files on my computer (WinXP pro, OfficeXP), and it works fine.
However, when I run this programme on another computer (Win98, OfficeXP) the programme is unable to find the file(s). Has this something to do with the Operating System, or File Index updating?

I hope anyone knows a solution to this problem. THanks in advance

Max

Dim drives(2) As Variant
Dim addin_name As String
' identify the driveletter(s) of the harddisk(s)
Set fs = CreateObject("Scripting.FileSystemObject")
Set dc = fs.drives
k = 0
For Each d In dc
    s = d.DriveLetter
 ' MsgBox "s = " & s
    If d.DriveType = 2 Then ' drivetype = 2 are all fixed harddisks
' MsgBox "drivetype = 2"
        k = k + 1
        drives(k) = s
    End If
Next
'
For k = 1 To 2
    With Application.FileSearch
        .NewSearch
' MsgBox "drives(k) & ':' = " & drives(k) & ":"
        .LookIn = drives(k) & ":"
        .SearchSubFolders = True
        .Filename = "AddIn_V3.xla"
        .MatchTextExactly = True
    If .Execute() > 0 Then
' MsgBox "files found"
        addin_name = .FoundFiles(1)
        GoTo continue
    Else
        MsgBox "No admin file found....."
    End If
    End With
Next k
continue:
For k = 1 To 2
    With Application.FileSearch
        .NewSearch
' MsgBox "drives(k) & ':' = " & drives(k) & ":"
        .LookIn = drives(k) & ":"
        .SearchSubFolders = True
        .Filename = "EEE7.ico"
        .MatchTextExactly = True
    If .Execute() > 0 Then
' MsgBox "files found"
        icon_path = .FoundFiles(1)
    Else
        MsgBox "No admin file found....."
    End If
    End With
Next k

Workbooks(wrb).Sheets("Sheet1").Unprotect
Workbooks(wrb).Sheets("Sheet1").Range("N30").Value = addin_name
Workbooks(wrb).Sheets("Sheet1").Range("N31").Value = icon_path
ThisWorkbook.VBProject.References.AddFromFile addin_name
 
Old February 23rd, 2005, 02:30 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 150
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Maybe FAT32 used in Win98 could be the problem. To my knowledge NTFS preserves the U/L case whereas FAT32 doesn't. Try change MatchTextExactly to False or change the filenames.
 
Old February 23rd, 2005, 03:03 PM
Authorized User
 
Join Date: Feb 2005
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

that's an interesting point, and i tried your tip, but still the files cannot be found.
 
Old February 23rd, 2005, 03:23 PM
Authorized User
 
Join Date: Feb 2005
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

birger, i have noticed something perculiar. When i replace the files to, for example, My Documents, the programme is able to find the files, but when i put them back to the place where i originally stored them (Desktop) it is not able to find them. Is this due to the fact that Desktop isnt a folder?
 
Old February 23rd, 2005, 03:48 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 150
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I don't have W98 running anymore, so I can't say. However, from a file point of view, if you can address the folders (Desktop or any other) from a dos-prompt, I would regard them as folders. I usually tests path problems in dos to avoid unseen restrictions or whatever the system try to hide for me. But to be honest, I don't know why that problem occurs.
 
Old February 23rd, 2005, 04:15 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 168
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
I have the same problem after I updated my Office from XP to 2003.
I have to go back to Dir-function, but I cant search the subdirectories anymore.

-vemaju

 
Old February 23rd, 2005, 05:19 PM
Authorized User
 
Join Date: Feb 2005
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok thanks for your replies. Do you have another way of searching the HDD for files in VBA?
thanks in advance

max





Similar Threads
Thread Thread Starter Forum Replies Last Post
Set fs = application.filesearch yismen Excel VBA 0 May 25th, 2007 02:18 PM
FileSearch Extension Problems JohnSmith Excel VBA 0 May 24th, 2007 07:04 PM
login fails... yasminnnnn ASP.NET 2.0 Basics 6 December 12th, 2006 03:49 PM
CreateObject fails slam Javascript 1 October 6th, 2006 10:32 AM
Protection method fails maxpotters Excel VBA 0 October 6th, 2005 05:35 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.