Results 1 to 3 of 3

Thread: [RESOLVED] Excel HYPERLINK formula using function

  1. #1

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Resolved [RESOLVED] Excel HYPERLINK formula using function

    Trying to make this work..

    In col E i have the folder name.. in Col D i want the Hyperlink.

    so i am using the formula =HYPERLINK(thePath(D5,-1))

    this code should also put a TRUE or FALSE in col F if the folder exists... but nope lol
    Code:
    Public Function thePath(pth As Range, Optional offset As Integer = 0) As String
    Dim YR As String
    Dim MMYYY As String
    Dim dPath As String
    Dim DT As Date
    
    DT = DateAdd("m", offset, Date)
    
    MMYYYY = Format(DT, "MM-YYYY")
    YR = Year(DT)
    
    thePath = "\\xxxxxxxNetworkPathxxxx\ntusers\Line Cost\Reporting\" & YR & " Close Reports\" & MMYYYY & "\" & pth.Value
    
    
    'Exit Function  <<< NOTE THIS
    
    
    If Len(Dir(thePath, vbDirectory)) > 0 Then
        ActiveSheet.Cells(pth.Row, pth.Column + 1).Value = "TRUE"
    Else
        ActiveSheet.Cells(pth.Row, pth.Column + 1).Value = "FALSE"
    End If
    End Function
    as is, i get the TRUE, but the hyperlink cell says #VALUE!
    if I uncomment the Exit, then the path show correctly, but obviously the True False doesnt work.

    any ideas??


    FYI: I also tried using another function to check the Dir, =PathCheck(D5)

    Code:
    Public Function PathCheck(sPath As Range) As String
    
    Dim pLen As Long
    Dim pStr As String
    
    pLen = Len(Dir(sPath.Text, vbDirectory))
    
    If pLen > 0 Then
        PathCheck = "TRUE"
    Else
        PathCheck = "FALSE"
        
    End If
    
    End Function
    returns false!?? lol even though it does exist?! lol
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel HYPERLINK formula using function

    i tested your second function, worked fine for me

    this code should also put a TRUE or FALSE in col F if the folder exists
    no, you can not do this with a worksheet function, give them their own formula

    when i tested the code it was failing on
    If Len(Dir(thepath, vbDirectory)) > 0 Then
    without error
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Excel HYPERLINK formula using function

    ok.. well im stumped. It works today (using the PathCheck function)

    ?????

    I guess... thanks? lol
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

Posting Permissions

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



Click Here to Expand Forum to Full Width