Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Link to file in subdirectory
Hi all,
I am a Excel & VBA newbie and I have to do this kind of script : in column A, I have a liste of reference. Example : "R-AD-H-F" in a directory, call it '\myDir\', I have many subdirectories whith a lot of files. File format is, for example, "R AD H F.APJ" = I need to put in column B a list of link to file in '\myDir\' for each reference in column A Any ideas ? Thanks. Best regards, Matthieu. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Link to file in subdirectory
Folder = "\myDir" Extension = "apj" RowCount = 1 Do While Range("A" & RowCount) < "" MyFile = Folder & "\" & Range("A" & RowCount) & _ "." & "Extension" Range("B" & RowCount).Hyperlinks.Add _ Anchor:=Selection, _ Address:=MyFile, _ TextToDisplay:=MyFile RowCount = RowCount + 1 Loop "Matthieu B." wrote: Hi all, I am a Excel & VBA newbie and I have to do this kind of script : in column A, I have a liste of reference. Example : "R-AD-H-F" in a directory, call it '\myDir\', I have many subdirectories whith a lot of files. File format is, for example, "R AD H F.APJ" = I need to put in column B a list of link to file in '\myDir\' for each reference in column A Any ideas ? Thanks. Best regards, Matthieu. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Link to file in subdirectory
Hi Joel, and thank you for your awnser ! Its a good begining, but what I have to do is a bit more difficult. Excuse me for my misexplanation. My files are not all in the directory 'MyDir'. There are a lot of subdirectories, with various names convention. I need a function that recursively find the file location with a filter function. Exemple : cell A1 contains "A-ZER-TY" the file to link to is in \MyDir\projetct\projectblablabla\AZERTY.APJ I need to put a link in B1 to this file And so from A1 to Ax. But I like to thank you a lot for your awnser. It's a nice begining for me and I will try to work on it to improve your function. If anyone have others suggestions, you are welcome ! Best regards, Matthieu |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Link to file in subdirectory
It took me a couple of minutes to modify another macro I had. the code
recursively goes through all subdirectories and then make the link. Sub GetLinks() ' ' Macro1 Macro ' Macro recorded 3/2/2008 by Joel ' ' strFolder = '"\myDir\" 'make sure you leave last backslash Extension = "apj" RowCount = 1 Do While Range("A" & RowCount) < "" location = "" MyFile = Range("A" & RowCount) & "." & Extension Call GetSubFolderSize(strFolder, MyFile, location) if location < "" then MyFile = location & Range("A" & RowCount) & _ "." & Extension Range("B" & RowCount).Hyperlinks.Add _ Anchor:=Range("B" & RowCount), _ Address:=MyFile, _ TextToDisplay:=MyFile end if RowCount = RowCount + 1 Loop End Sub Sub GetSubFolderSize(strFolder, MyFile, ByRef location) Set fso = CreateObject _ ("Scripting.FileSystemObject") Set folder = _ fso.GetFolder(strFolder) If folder.subfolders.Count 0 Then For Each sf In folder.subfolders On Error GoTo 100 Call GetSubFolderSize(strFolder + sf.Name + "\", _ MyFile, location) If location < "" Then Exit For 100 Next sf End If 'folder size in bytes On Error GoTo 200 If location = "" Then If Not folder.isrootfolder Then FName = Dir(strFolder & MyFile) If FName < "" Then location = strFolder End If End If End If 200 On Error GoTo 0 End Sub "Matthieu B." wrote: Hi Joel, and thank you for your awnser ! Its a good begining, but what I have to do is a bit more difficult. Excuse me for my misexplanation. My files are not all in the directory 'MyDir'. There are a lot of subdirectories, with various names convention. I need a function that recursively find the file location with a filter function. Exemple : cell A1 contains "A-ZER-TY" the file to link to is in \MyDir\projetct\projectblablabla\AZERTY.APJ I need to put a link in B1 to this file And so from A1 to Ax. But I like to thank you a lot for your awnser. It's a nice begining for me and I will try to work on it to improve your function. If anyone have others suggestions, you are welcome ! Best regards, Matthieu |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Link to file in subdirectory
Hi Joel, I don't know how to thank you Joel for this job. Thank you very much for taking time to modify your maccro. Your script works great ! Thank you very very much. You are outstanding. Best regards, Matthieu |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
need subdirectory check 99 | Excel Programming | |||
searching for a worksheet name while going through a subdirectory | Excel Programming | |||
Return most recent file in subdirectory with out using FileSearch | Excel Programming | |||
Saving to subdirectory using date() | Excel Programming | |||
Find Correct Subdirectory | Excel Programming |