+ Reply to Thread
Results 1 to 2 of 2

Inserting Hyperlinks to each image in a directory

Hybrid View

  1. #1
    YehWei@gmail.com
    Guest

    Inserting Hyperlinks to each image in a directory

    Hi,

    I would like to add hyperlinks to my digital collection which will
    always be stored in \Digital Camera\.

    The subsequent directories may change. So the problem now is how do I
    do it programmatically to sequentially search through all the
    directories and each each image under the directory as a hyperlink in a
    worksheet? A sample of the code for manual addition is shown below.

    Any help is appreciated. Thanks!

    ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
    "D:\1 Data\Personal\Digital
    Camera\Australia\100_1027\IMGP0471.JPG", _
    TextToDisplay:= _
    "D:\1 Data\Personal\Digital
    Camera\Australia\100_1027\IMGP0471.JPG"
    Range("A2").Select
    ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
    "D:\1 Data\Personal\Digital
    Camera\Australia\101_1028\IMGP0475.JPG", _
    TextToDisplay:= _
    "D:\1 Data\Personal\Digital
    Camera\Australia\101_1028\IMGP0475.JPG"


  2. #2
    Dave Peterson
    Guest

    Re: Inserting Hyperlinks to each image in a directory

    I like to use the =hyperlink() formula when I have lots of them.

    Option Explicit
    Sub testme()

    Dim wks As Worksheet
    Dim myPath As String
    Dim oRow As Long
    Dim iCtr As Long

    Set wks = Worksheets.Add
    wks.Range("a1").Value = "Filename"

    myPath = "C:\my documents\my pictures"

    With Application.FileSearch
    .NewSearch
    .LookIn = myPath
    .Filename = ".jpg"
    If .Execute() > 0 Then
    oRow = 1
    For iCtr = 1 To .FoundFiles.Count
    oRow = oRow + 1
    wks.Cells(oRow, "A").Formula _
    = "=hyperlink(""" & .FoundFiles(iCtr) & """)"
    Next iCtr
    End If
    End With

    wks.UsedRange.Columns.AutoFit

    End Sub

    If you don't like this, maybe you can adapt it to the Insert|hyperlink style.


    YehWei@gmail.com wrote:
    >
    > Hi,
    >
    > I would like to add hyperlinks to my digital collection which will
    > always be stored in \Digital Camera\.
    >
    > The subsequent directories may change. So the problem now is how do I
    > do it programmatically to sequentially search through all the
    > directories and each each image under the directory as a hyperlink in a
    > worksheet? A sample of the code for manual addition is shown below.
    >
    > Any help is appreciated. Thanks!
    >
    > ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
    > "D:\1 Data\Personal\Digital
    > Camera\Australia\100_1027\IMGP0471.JPG", _
    > TextToDisplay:= _
    > "D:\1 Data\Personal\Digital
    > Camera\Australia\100_1027\IMGP0471.JPG"
    > Range("A2").Select
    > ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
    > "D:\1 Data\Personal\Digital
    > Camera\Australia\101_1028\IMGP0475.JPG", _
    > TextToDisplay:= _
    > "D:\1 Data\Personal\Digital
    > Camera\Australia\101_1028\IMGP0475.JPG"


    --

    Dave Peterson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1