+ Reply to Thread
Results 1 to 4 of 4

Userform that inserts hyperlink for a file location

Hybrid View

  1. #1
    Registered User
    Join Date
    07-10-2014
    Location
    Florida
    MS-Off Ver
    2007
    Posts
    2

    Userform that inserts hyperlink for a file location

    I have created Browse buttons on my userform that open the file dialogue box, and allow me to select a file location. The file name text gets inserted into a corresponding text box. When the userform is submitted, the information goes to a database and is distribtued on the first empty row. The file names get inserted into cells, and I would like for the file names to act as hyperlinks to that specific file location. When I first created this workbook, I could click on the file location, and the file would open, but it is not doing that any longer. I think if the userform can insert the file location as a hyperlink, it will be more user-friendly. Here is the code I have so far:

    Private Sub BrowseButton_Click()
    'Browse for file
      Dim fullfilename As String
        
        filename = Application.GetOpenFilename()
        txtAttachChit.Value = filename
        txtAttachChit.SetFocus
        
    End Sub
    
    Private Sub BrowseButton2_Click()
    'Browse for file
        Dim filename As String
        
        filename = Application.GetOpenFilename()
        txtAttachOther.Value = filename
        txtAttachOther.SetFocus
    
    End Sub
    
    Private Sub cmdClose_Click()
        frmInquiry.Hide
    End Sub
    
    Private Sub cmdUpdate_Click()
    Dim iRow As Long
    Dim ws As Worksheet
    Set ws = Worksheets("Master Inquiry")
    
    'find first empty row in database
    iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
        SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
    
    'check for an Inquiry Date
    If Trim(Me.txtInquiryDate.Value) = "" Then
      Me.txtInquiryDate.SetFocus
      MsgBox "Please enter an Inquiry Date", vbOKOnly, "Entry Required"
      Exit Sub
    End If
    
    
    
    With ws
    If OptionButton1.Value = True Then
      .Cells(iRow, 1).Value = "F&B"
    End If
     If OptionButton2.Value = True Then
      .Cells(iRow, 1).Value = "Golf"
    End If
      If OptionButton3.Value = True Then
      .Cells(iRow, 1).Value = "Sports"
    End If
      If OptionButton4.Value = True Then
      .Cells(iRow, 1).Value = "Events"
    End If
      If OptionButton5.Value = True Then
      .Cells(iRow, 1).Value = "Membership"
    End If
      If OptionButton6.Value = True Then
      .Cells(iRow, 1).Value = "Other"
    End If
      .Cells(iRow, 2).Value = Me.txtInquiryDate.Value
      .Cells(iRow, 3).Value = Me.txtMemberName.Value
      .Cells(iRow, 4).Value = Me.txtMemberNumber.Value
      .Cells(iRow, 5).Value = Me.txtPhoneNumber.Value
      .Cells(iRow, 6).Value = Me.txtDate.Value
      .Cells(iRow, 7).Value = Me.txtAmount.Value
      .Cells(iRow, 8).Value = Me.txtDescription
      .Cells(iRow, 9).Value = Me.txtAttachChit
      .Cells(iRow, 10).Value = Me.txtAttachOther
      .Cells(iRow, 11).Value = Me.txtSentBy.Value
      .Cells(iRow, 13).Value = "Outstanding"
    
    
    End With
    
    'clear the data
        Me.txtInquiryDate.Value = ""
        Me.txtMemberName.Value = ""
        Me.txtMemberNumber.Value = ""
        Me.txtPhoneNumber.Value = ""
        Me.txtDate.Value = ""
        Me.txtAmount.Value = ""
        Me.txtDescription = ""
        Me.txtDescription = ""
        Me.txtAttachChit = ""
        Me.txtAttachOther = ""
        Me.txtSentBy = ""
        Me.OptionButton1 = False
        Me.OptionButton2 = False
        Me.OptionButton3 = False
        Me.OptionButton4 = False
        Me.OptionButton5 = False
        Me.OptionButton6 = False
        Me.txtInquiryDate.SetFocus
    
    End Sub
    Last edited by lowell.addi; 07-17-2014 at 02:12 PM.

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Userform that inserts hyperlink for a file location

    Welcome to the board!

    Try this.
    .Cells(iRow, 10).Hyperlink.Add .Cells(iRow, 10), Me.txtAttachOther
    David
    (*) Reputation points appreciated.

  3. #3
    Registered User
    Join Date
    07-10-2014
    Location
    Florida
    MS-Off Ver
    2007
    Posts
    2

    Re: Userform that inserts hyperlink for a file location

    Tinbendr:

    I inserted your code in place of mine, and I am getting a "Run-time error 438: Object doesn't support this property or method". Any suggestions?

  4. #4
    Forum Contributor pareshj's Avatar
    Join Date
    05-20-2014
    Location
    MUMBAI
    MS-Off Ver
    2007 & 2010
    Posts
    447

    Re: Userform that inserts hyperlink for a file location

    Hi,

    Check the below code and hope this will help you:

    ThisWorkbook.Sheets("YourSheetName").Range("A1").Formula = "=HYPERLINK(""" & Filepath & """,""" & Filepath & """)"
    Where
    YourSheetName = Name of the sheet on which you want hyperlink function
    And A1 is the cell where Hyperlink function will be placed.
    And Filepath = Your file path for eg: "D:\abc.txt"

    Regards,
    Paresh J
    Click on "* Add Reputation" as a way to say thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Excel Hyperlink to location within same file from word within cell
    By dave1983 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-23-2014, 11:38 AM
  2. Excel VBA in a userform that create a hyperlink into a specific cell location
    By mikeflatley01 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 01-19-2013, 08:04 PM
  3. Copy hyperlink file to another location and give it a new file name
    By karole in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-26-2012, 03:50 PM
  4. Automatic Hyperlink to File Location/Path on Server
    By dforte in forum Excel General
    Replies: 6
    Last Post: 04-15-2011, 02:53 PM
  5. Replies: 1
    Last Post: 10-05-2005, 07:05 PM

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