PC Review


Reply
Thread Tools Rate Thread

Extract & create hyperlink of files in excel

 
 
New Member
Join Date: Jun 2008
Posts: 1
 
      20th Jun 2008
Hi,

I have thousands of files in a folder and I want to extract the part of filename and create hyperlinks. My files in a folder (microarray) look like this:
US45102950_251655210078_Feb07_1.jpg
US45102950_251655210078_Feb07_1.pdf
US45102950_251655210078_Feb07_2.jpg
US45102950_251655210078_Feb07_2.jpg

My excel file sholud look like this

US45102950 251655210078 Feb07 1 link of jpg link of pdf
US45102950 251655210078 Feb07 2 link of jpg link of pdf

Actually each file has two different extenstions like jpg and pdf but the filename is same. I want to extract the information of filename after "_" in different column and with their hyperlinks of jpg and pdf files in a single row.

I am new in VBA programming.Please help me in making the code using Macro programming in excel.

Thanks in advance

Manish
 
Reply With Quote
 
 
 
 
New Member
Join Date: Dec 2008
Posts: 6
 
      7th Dec 2008
Option Explicit

'Jobs to do:
'1) Extract filenames
'2) Remove duplicates; filename for jpg & pdf extension
'3) Insert link

' !!!WARNING!!!
'Before you run procedure Jobs2Do
'In cell A1 enter "Oryginal FileName"
'In cell B1 enter "New FileName"
'In cell C1 enter "Link of jpg"
'In cell B1 enter "Link of pdf"
'It's your columnheader's; bold'em
Now, sort the range in your source sheet by column Oryginal FileName - Asc
'copy source sheet

Sub Jobs2Do()
Dim wsh As Worksheet
Dim i As Integer
Dim sOldFName As String, sNewFName As String

On Error GoTo Err_Jobs2Do

'create var of object: Worksheet
Set wsh = ThisWorkbook.Worksheets("Sh1")
i = 2 'var: counter
Do While wsh.Range("A" & i) <> "" '
sOldFName = wsh.Range("A" & i)
sNewFName = Left(sOldFName, Len(sOldFName) - 4) 'remove last 4 sighns
sNewFName = Replace(sNewFName, "_", " ") 'replace "_" with space
'insert new file name
wsh.Range("B" & i) = sNewFName
'remove duplicates
If Left(wsh.Range("A" & i + 1), Len(sOldFName) - 4) = Left((sOldFName), Len(sOldFName) - 4) Then
wsh.Range("A" & i + 1).EntireRow.Delete
End If
'extract file name without extension
sOldFName = Left(sOldFName, Len(sOldFName) - 3) 'remove extension
'insert link of jpg
InsertLink wsh.Range("C" & i), sOldFName & "jpg"
'insert link of jpg
InsertLink wsh.Range("D" & i), sOldFName & "pdf"
i = i + 1
Loop

Exit_Jobs2Do:
On Error Resume Next
Set wsh = Nothing 'free up memory
Exit Sub
Err_Jobs2Do:
Resume Exit_Jobs2Do
End Sub


Sub InsertLink(rng As Range, sFileName As String)

On Error GoTo Err_InsertLink

Worksheets(rng.Parent.Name).Hyperlinks.Add _
Anchor:=rng, Address:=sFileName, TextToDisplay:="link"

Exit_InsertLink:
Exit Sub

Err_InsertLink:
Resume Exit_InsertLink
End Sub
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Programming to extract automatically extract attachments Nelson The Missing Lead Microsoft Outlook VBA Programming 1 8th Mar 2010 09:23 AM
extract vista I can extract vista from the iso file but can not ex =?Utf-8?B?ZmpqbTMwMw==?= Windows Vista General Discussion 7 20th Jun 2006 01:46 AM
Extract Unique Values, Then Extract Again to Remove Suffixes Karl Burrows Microsoft Excel Discussion 23 25th Jun 2005 10:37 PM
Extract Unique Values, Then Extract Again to Remove Suffixes Karl Burrows Microsoft Excel Misc 23 25th Jun 2005 10:37 PM
To Extract or Not to Extract that is the Question =?Utf-8?B?UmhvXzFy?= Windows XP General 0 16th Sep 2004 05:49 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:51 PM.