Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

“.FileName”

Status
Not open for further replies.

johnmtb

Programmer
Jul 12, 2008
37
US
Dear All,

I cannot understand why the following code does not work, when a previous programme using the same code works perfectly.

I am trying to obtain the complete name of a file, when I know part of that name, the part that I know being 521026. The “*.*”, should provide the remainder of the file name, but all I get is “521026*.*”. Why?

This is the code:

Code:
With Application.FileSearch
     .LookIn = "C:\X\Finance\"
     .FileName = CellStatus & "*.*"
     If .Execute > 0 Then
          Call SetHyperlink
     Else
          GoTo LookAgain
     End If
End With

"C:\X\Finance\" is the folder, and CellStatus is read by another part of the programme. I am expecting the file name to be "521026 WT0841.pdf".

What I really want to know is, why doesn’t the wildcard “*” expand?

Regards,

john
 
Hi,

What does SetHyperlink do?

Please post this code.

BTW, I got this basic method to work as advertised.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
SkipVoughht,

that code has not been written yet. i normally break my coding into chunks of things to do. i haven't got to that yet, as it will use the results of the code above to choose the item to be hyperlinked into a position on the master Excel sheet.

regards,

john
 

Check this out...
Code:
Sub test()
Dim CellStatus, i
CellStatus = "521026"
With Application.FileSearch
     .LookIn = "C:\X\Finance\"
     .Filename = CellStatus & "*.*"
     If .Execute > 0 Then
        For i = 1 To .FoundFiles.Count
            MsgBox .FoundFiles(i)
        Next i
    Else
    MsgBox "There were no files found."
    End If
End With
End Sub


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Skip,

thank you, but it gives the same result. it just doesn't expand the *.*.

regards,

john
 
Please explain exactly how you come to this conclusion. What actually happens when you run this code?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Skip,

i run it until the end of the SUB(), then i hold it there with a break point. i can then read the .Filename, which shows only "521026*.*". on my other programme, it would show, for example only, "521026 WT0841.pdf".

regards,

john
 
Then you are NOT running MY code that I posted.

What happend when you run the code I posted???

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Skip,

sorry, i thought i had run your code, but when i checked again, i had not.

thank you, indeed your code gives me the full file name.

regards,

john
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top