Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Search for name of a file in a directory (http path)
(Excel 2003)
Thought this would be simple, but I'm having problems. I ultimately want to open an xls file, but first have to get the file name because it changes. So, I need to return the xls file name that begins with a given prefix from a certain folder. Only one such file will exist in the folder. It always begins with "YTD Stats", but its full name will change several times per year. It may be "YTD Stats June - RevA" and then the next week change to "YTD Stats June - RevB". Plus the month string can change. So, the only constants are the path, it's an XLS file, and it begins with "YTD Stats". The code below reflects the task and works fine when the path is a normal Windows type folder and drive. But it fails when I use an HTTP path. (Users DO have access permission to the path and successfully open files using the path in code.) So, can the code below be modified to work with an http path? If not, what are some other suggestions to find the xls file name based on a prefix and using an http path? (If I can't make this work programmatically, I'll have to make the user input it, which will be a real hassle for them being it changes without warning. I'm really hoping someone knows of a solution.) Thank you for helping, Daisy Sub GetWkbkName() 'Find the workbook name within a folder that matches a given prefix. Dim strPath As String, strPrefix As String strPath = "http://mycompany.com/firewall/tsp/shared%20documents" strPrefix = "YTD Stats" Dim rw As Long, i As Long With Application.FileSearch .NewSearch .LookIn = strPath .SearchSubFolders = False .Filename = strPrefix & "*.xls" .FileType = msoFileTypeExcelWorkbooks If .Execute() 0 Then For i = 1 To .FoundFiles.Count Range("a1").Value = Dir(.FoundFiles(i)) Exit For Next i Else MsgBox "Error - No stat files found." End If End With End Sub |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Search for name of a file in a directory (http path)
Daisy,
Assuming the server supports FTP also, this would be my route, although others may have other suggestions. Whilst this may look rather daunting, it is relatively simple. Also, once mastered, adding functionality (create/kill folders/files) is straight-forward. http://vbnet.mvps.org/code/internet/ftplist.htm There is also the Inet control NickHK "Daisy P" wrote in message oups.com... (Excel 2003) Thought this would be simple, but I'm having problems. I ultimately want to open an xls file, but first have to get the file name because it changes. So, I need to return the xls file name that begins with a given prefix from a certain folder. Only one such file will exist in the folder. It always begins with "YTD Stats", but its full name will change several times per year. It may be "YTD Stats June - RevA" and then the next week change to "YTD Stats June - RevB". Plus the month string can change. So, the only constants are the path, it's an XLS file, and it begins with "YTD Stats". The code below reflects the task and works fine when the path is a normal Windows type folder and drive. But it fails when I use an HTTP path. (Users DO have access permission to the path and successfully open files using the path in code.) So, can the code below be modified to work with an http path? If not, what are some other suggestions to find the xls file name based on a prefix and using an http path? (If I can't make this work programmatically, I'll have to make the user input it, which will be a real hassle for them being it changes without warning. I'm really hoping someone knows of a solution.) Thank you for helping, Daisy Sub GetWkbkName() 'Find the workbook name within a folder that matches a given prefix. Dim strPath As String, strPrefix As String strPath = "http://mycompany.com/firewall/tsp/shared%20documents" strPrefix = "YTD Stats" Dim rw As Long, i As Long With Application.FileSearch .NewSearch .LookIn = strPath .SearchSubFolders = False .Filename = strPrefix & "*.xls" .FileType = msoFileTypeExcelWorkbooks If .Execute() 0 Then For i = 1 To .FoundFiles.Count Range("a1").Value = Dir(.FoundFiles(i)) Exit For Next i Else MsgBox "Error - No stat files found." End If End With End Sub |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Search for name of a file in a directory (http path)
So, FileSearch cannot work with an http path? Am I seeing that
correctly? Daisy On Apr 18, 11:00 pm, Daisy P wrote: (Excel 2003) Thought this would be simple, but I'm having problems. I ultimately want to open an xls file, but first have to get the file name because it changes. So, I need to return the xls file name that begins with a given prefix from a certain folder. Only one such file will exist in the folder. It always begins with "YTD Stats", but its full name will change several times per year. It may be "YTD Stats June - RevA" and then the next week change to "YTD Stats June - RevB". Plus the month string can change. So, the only constants are the path, it's an XLS file, and it begins with "YTD Stats". The code below reflects the task and works fine when the path is a normal Windows type folder and drive. But it fails when I use an HTTP path. (Users DO have access permission to the path and successfully open files using the path in code.) So, can the code below be modified to work with an http path? If not, what are some other suggestions to find the xls file name based on a prefix and using an http path? (If I can't make this work programmatically, I'll have to make the user input it, which will be a real hassle for them being it changes without warning. I'm really hoping someone knows of a solution.) Thank you for helping, Daisy Sub GetWkbkName() 'Find the workbook name within a folder that matches a given prefix. Dim strPath As String, strPrefix As String strPath = "http://mycompany.com/firewall/tsp/shared%20documents" strPrefix = "YTD Stats" Dim rw As Long, i As Long With Application.FileSearch .NewSearch .LookIn = strPath .SearchSubFolders = False .Filename = strPrefix & "*.xls" .FileType = msoFileTypeExcelWorkbooks If .Execute() 0 Then For i = 1 To .FoundFiles.Count Range("a1").Value = Dir(.FoundFiles(i)) Exit For Next i Else MsgBox "Error - No stat files found." End If End With End Sub |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Search for name of a file in a directory (http path)
Thanks for the FTP suggestion. I'm afraid, however, it's not doable
for me because I'd have to code in an ID and password, which I'm certain won't be given to me. It appears then that there's no way to search an http link for file names, even if it is behind our firewall and accessable. But, anyone with comments, fire away. In the meantime, I'm having IT write a routine that daily duplicates the needed file (with a CONSTANT name) into a normal shared drive that I can then access with a simple file open command. So far, they're cooperative about doing it. I'm keeping my fingers crossed. I just hate it that I wasn't able to handle this myself, but oh well. I tried. Daisy On Apr 19, 12:01 am, "NickHK" wrote: Daisy, Assuming the server supports FTP also, this would be my route, although others may have other suggestions. Whilst this may look rather daunting, it is relatively simple. Also, once mastered, adding functionality (create/kill folders/files) is straight-forward.http://vbnet.mvps.org/code/internet/ftplist.htm There is also the Inet control NickHK "Daisy P" wrote in message oups.com... (Excel 2003) Thought this would be simple, but I'm having problems. I ultimately want to open an xls file, but first have to get the file name because it changes. So, I need to return the xls file name that begins with a given prefix from a certain folder. Only one such file will exist in the folder. It always begins with "YTD Stats", but its full name will change several times per year. It may be "YTD Stats June - RevA" and then the next week change to "YTD Stats June - RevB". Plus the month string can change. So, the only constants are the path, it's an XLS file, and it begins with "YTD Stats". The code below reflects the task and works fine when the path is a normal Windows type folder and drive. But it fails when I use an HTTP path. (Users DO have access permission to the path and successfully open files using the path in code.) So, can the code below be modified to work with an http path? If not, what are some other suggestions to find the xls file name based on a prefix and using an http path? (If I can't make this work programmatically, I'll have to make the user input it, which will be a real hassle for them being it changes without warning. I'm really hoping someone knows of a solution.) Thank you for helping, Daisy Sub GetWkbkName() 'Find the workbook name within a folder that matches a given prefix. Dim strPath As String, strPrefix As String strPath = "http://mycompany.com/firewall/tsp/shared%20documents" strPrefix = "YTD Stats" Dim rw As Long, i As Long With Application.FileSearch .NewSearch .LookIn = strPath .SearchSubFolders = False .Filename = strPrefix & "*.xls" .FileType = msoFileTypeExcelWorkbooks If .Execute() 0 Then For i = 1 To .FoundFiles.Count Range("a1").Value = Dir(.FoundFiles(i)) Exit For Next i Else MsgBox "Error - No stat files found." End If End With End Sub- Hide quoted text - - Show quoted text - |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
http://CannotDeleteFile.net - Cannot Delete File? Try Long Path ToolFilename is too long? Computer Complaining Your Filename Is Too Long? TheLong Path Tool Can Help While most people can go about their businessblissfully unaware of the Windo | Excel Discussion (Misc queries) | |||
Saving txt file from excel by specifying path - drop down directory explorer | Excel Programming | |||
How to ascertain path of file in adjacent directory hierarchy | Excel Programming | |||
How do I insert the directory path in my Excel file? | Excel Worksheet Functions | |||
get path - save new file - same sub-directory as existing file | Excel Programming |