Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
need subdirectory check 99 Ray Excel Programming 2 October 9th 06 04:59 PM
searching for a worksheet name while going through a subdirectory ibbm Excel Programming 2 March 27th 06 09:12 PM
Return most recent file in subdirectory with out using FileSearch Enohp Aikon Excel Programming 20 October 3rd 05 11:24 PM
Saving to subdirectory using date() pvm3911 Excel Programming 1 August 24th 05 07:27 AM
Find Correct Subdirectory Stratuser Excel Programming 1 November 15th 04 11:56 PM


All times are GMT +1. The time now is 03:32 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"