+ Reply to Thread
Results 1 to 8 of 8

Auto Hyperlink to existing cell value

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-10-2012
    Location
    istanbul
    MS-Off Ver
    Excel 2013
    Posts
    297

    Auto Hyperlink to existing cell value

    In my file, a macro gets the file path to starting from B11 to B(n), meaning 1 ,1000 or 20.000 file name in B column.
    Starting to B11 to B last row filling with path names, for example "E:\FILMs\The Thin Red Line.avi" etc. This is the full path of the file.

    I need to make hyperlink for each row cell value with an additional macro codes which will make auto hyperlinks when first macro ended.

    Like "Private Sub Worksheet_Activate()" or "Private Sub Worksheet_SelectionChange(ByVal Target As Range)"

    Or any idea or code will be acceptable.

    Thanks in advance for replies.

    Regards,
    turist

  2. #2
    Valued Forum Contributor
    Join Date
    11-20-2012
    Location
    Seattle, WA USA
    MS-Off Ver
    Excel 2010
    Posts
    597

    Re: Auto Hyperlink to existing cell value

    why cant you use call macroname? then have the code to create the hyperlink

    or

    I'm guessing that you are using a loop to pull in the file names so why not add the code before the next command

    post your code so we can see what you are trying to do, post your workbook (or an example) if your code is vauge
    Last edited by scott.s.fower; 04-25-2013 at 08:04 PM.

  3. #3
    Forum Contributor
    Join Date
    11-10-2012
    Location
    istanbul
    MS-Off Ver
    Excel 2013
    Posts
    297

    Re: Auto Hyperlink to existing cell value

    Quote Originally Posted by scott.s.fower View Post
    why cant you use call macroname? then have the code to create the hyperlink

    or

    I'm guessing that you are using a loop to pull in the file names so why not add the code before the next command

    post your code so we can see what you are trying to do, post your workbook (or an example) if your code is vauge
    Here is macro code:
    Sub ListMyFiles()
    Range("B11:f65536") = Clear
        Call ListFiles(Range("C7").Value, Range("B11:F11"), Range("C8").Value)
        
    End Sub
    
    Sub ListFiles(ByVal FilePath As Variant, ByRef OutRng As Range, Optional ByVal ListSubfolders As Boolean)
    
        Dim Created As Variant
        Dim FileSize As String
        Dim oFile As Object
        Dim oFolder As Object
        Dim oShell As Object
        Dim r As Long
        Dim SubFolder As Variant
        Dim SubFolders As Collection
        Dim VideoLength As String
        
            Set oShell = CreateObject("Shell.Application")
            Set oFolder = oShell.Namespace(FilePath)
            
            If oFolder Is Nothing Then
                MsgBox FilePath & " BULUNAMADI!", vbExclamation
                Exit Sub
            End If
            
            If SubFolders Is Nothing Then Set SubFolders = New Collection
            
                For Each oItem In oFolder.Items
                    With oItem
                        If .IsFolder Then
                            SubFolders.Add oItem.Path
                        End If
                        
                        FileSize = oFolder.GetDetailsOf(oItem, 1)
                        Created = oFolder.GetDetailsOf(oItem, 4)
                        VideoLength = oFolder.GetDetailsOf(oItem, 27)
                        
                        If .IsFileSystem Then
                            OutRng.Offset(r, 0).Value = Array(.Path, .Name, FileSize, Created, VideoLength)
                            r = r + 1
                        End If
                    End With
                Next oItem
                
                If ListSubfolders Then
                    Set OutRng = OutRng.Offset(r, 0)
                    For Each SubFolder In SubFolders
                        Call ListFiles(SubFolder, OutRng, True)
                    Next SubFolder
                End If
                
    End Sub
    And attached file explained the requierment.

    Thanks in advance for any help.
    Attached Files Attached Files
    Last edited by turist; 04-26-2013 at 11:58 AM.

  4. #4
    Forum Contributor
    Join Date
    11-10-2012
    Location
    istanbul
    MS-Off Ver
    Excel 2013
    Posts
    297

    Re: Auto Hyperlink to existing cell value

    Waiting for any comment or solution.

  5. #5
    Valued Forum Contributor
    Join Date
    11-20-2012
    Location
    Seattle, WA USA
    MS-Off Ver
    Excel 2010
    Posts
    597

    Re: Auto Hyperlink to existing cell value

    hey, so when you click the hyperlink do you want it to open or do you want it to open the folder that contains it?

    right now it opens the file... (should be dependent on your default player)

    replace your sub with this modified one
    Sub ListFiles(ByVal FilePath As Variant, ByRef OutRng As Range, Optional ByVal ListSubfolders As Boolean)
    
        Dim Created As Variant
        Dim FileSize As String
        Dim oFile As Object
        Dim oFolder As Object
        Dim oShell As Object
        Dim r As Long
        Dim SubFolder As Variant
        Dim SubFolders As Collection
        Dim VideoLength As String
        
            Set oShell = CreateObject("Shell.Application")
            Set oFolder = oShell.Namespace(FilePath)
            
            If oFolder Is Nothing Then
                MsgBox FilePath & " NOT FOUND!", vbExclamation
                Exit Sub
            End If
            
            If SubFolders Is Nothing Then Set SubFolders = New Collection
            
                For Each oItem In oFolder.Items
                    With oItem
                        If .IsFolder Then
                            SubFolders.Add oItem.Path
                        End If
                        
                        FileSize = oFolder.GetDetailsOf(oItem, 1)
                        Created = oFolder.GetDetailsOf(oItem, 4)
                        VideoLength = oFolder.GetDetailsOf(oItem, 27)
                        
                        If .IsFileSystem Then
    '''''''''''''modified part
                            p = .Path
                            hlink = "=HYPERLINK(""[" & p & "]"",""" & p & """)"
                            
                            OutRng.Offset(r, 0).Value = Array(hlink, .Name, FileSize, Created, VideoLength)
    '''''''''''''''''''''''''''''''''''''''''''                        
                            r = r + 1
                        End If
                    End With
                Next oItem
                
                If ListSubfolders Then
                    Set OutRng = OutRng.Offset(r, 0)
                    For Each SubFolder In SubFolders
                        Call ListFiles(SubFolder, OutRng, True)
                    Next SubFolder
                End If
                
    End Sub
    Last edited by scott.s.fower; 04-26-2013 at 02:34 PM.

  6. #6
    Forum Contributor
    Join Date
    11-10-2012
    Location
    istanbul
    MS-Off Ver
    Excel 2013
    Posts
    297

    Re: Auto Hyperlink to existing cell value

    Quote Originally Posted by scott.s.fower View Post
    hey, so when you click the hyperlink do you want it to open or do you want it to open the folder that contains it?
    I want to open the hyperlinked file (for example , if avi file in mediaplayer). NOT to open the folder.

  7. #7
    Forum Contributor
    Join Date
    11-10-2012
    Location
    istanbul
    MS-Off Ver
    Excel 2013
    Posts
    297

    Re: Auto Hyperlink to existing cell value

    Quote Originally Posted by scott.s.fower View Post
    hey, so when you click the hyperlink do you want it to open or do you want it to open the folder that contains it?

    right now it opens the file... (should be dependent on your default player)

    replace your sub with this modified one
    Sub ListFiles(ByVal FilePath As Variant, ByRef OutRng As Range, Optional ByVal ListSubfolders As Boolean)
    
        Dim Created As Variant
        Dim FileSize As String
        Dim oFile As Object
        Dim oFolder As Object
        Dim oShell As Object
        Dim r As Long
        Dim SubFolder As Variant
        Dim SubFolders As Collection
        Dim VideoLength As String
        
            Set oShell = CreateObject("Shell.Application")
            Set oFolder = oShell.Namespace(FilePath)
            
            If oFolder Is Nothing Then
                MsgBox FilePath & " NOT FOUND!", vbExclamation
                Exit Sub
            End If
            
            If SubFolders Is Nothing Then Set SubFolders = New Collection
            
                For Each oItem In oFolder.Items
                    With oItem
                        If .IsFolder Then
                            SubFolders.Add oItem.Path
                        End If
                        
                        FileSize = oFolder.GetDetailsOf(oItem, 1)
                        Created = oFolder.GetDetailsOf(oItem, 4)
                        VideoLength = oFolder.GetDetailsOf(oItem, 27)
                        
                        If .IsFileSystem Then
    '''''''''''''modified part
                            p = .Path
                            hlink = "=HYPERLINK(""[" & p & "]"",""" & p & """)"
                            
                            OutRng.Offset(r, 0).Value = Array(hlink, .Name, FileSize, Created, VideoLength)
    '''''''''''''''''''''''''''''''''''''''''''                        
                            r = r + 1
                        End If
                    End With
                Next oItem
                
                If ListSubfolders Then
                    Set OutRng = OutRng.Offset(r, 0)
                    For Each SubFolder In SubFolders
                        Call ListFiles(SubFolder, OutRng, True)
                    Next SubFolder
                End If
                
    End Sub
    Dear scott.s.fower

    Thanks a lot for your prompt reply.
    It is OK, worked.

    Regards,
    turist

  8. #8
    Valued Forum Contributor
    Join Date
    11-20-2012
    Location
    Seattle, WA USA
    MS-Off Ver
    Excel 2010
    Posts
    597

    Re: Auto Hyperlink to existing cell value

    k the code i gave you will open the file

+ 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