ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Hard-Coding a File Location (https://www.excelbanter.com/excel-programming/295220-hard-coding-file-location.html)

ibeetb

Hard-Coding a File Location
 
I have Excel files in a directory on the network that I want to be updated
even if they are moved WITHIN the SAME directory but say.....in another
subfolder. Right now, they are dependent on each other so I have the
location of them hard-coded . But if I move ONE, Excel wont be able to find
it. How can I not hard-code the location but still have them be able to find
each other?



Chris

Hard-Coding a File Location
 
Your gonna have use a filesearch in your code like this

Dim FCnt As Integer, MyFilePath As String, Fs As FileSearc
Set Fs = Application.FileSearc
With F
.LookIn = "C:\
.Filename = "MyFileName.xls
.FileType = msoFileTypeExcelWorkbook
.SearchSubFolders = Tru
If .Execute() 0 The
FCnt = .FoundFiles.Coun
MyFilePath = .FoundFiles(FCnt
Els
MsgBox "MyFileName could not be found!
Exit Su
End I
End With


All times are GMT +1. The time now is 08:15 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com