PDA

View Full Version : Hyperlink to folder



HV_L
01-24-2012, 12:27 PM
This the corrected version of an earlier post:
I finally can insert links in this post..
www.vbaexpress.com/forum/showthread.php?t=40640 (http://www.vbaexpress.com/forum/showthread.php?t=40640)

I posted in two other forums the same question, but not getting replies.
Cross posted here
www.vbforums.com/showthread.php?p=4122997 (http://www.vbforums.com/showthread.php?p=4122997)
and here
www.excelforum.com/excel-programming/810964-linking-to-folder.html (http://www.excelforum.com/excel-programming/810964-linking-to-folder.html)
Hopefully here I will.
Oke, the case:
I got in column A of my sheet nnumbers 1- 250.
I add new rows with a userform and set some formula's and the data from the Form in this new row.
I created manually hyperlinks from these numbers to a folder, looks like this:
=HYPERLINK("D:\Documents\AV\154";"154")
How can I let VBA grab this number out of this link, add one (becoming 155";"155" in this example and create a hyperlink from it?
The number to be found is always the last used row.

Code from userform:

Private Sub OpslaanButton_Click()

'Make Sheet digid Active
Sheets("digid").Activate

Dim emptyRow As Long
Dim ws As Worksheet
Set ws = Worksheets("digid")

'find first empty row in database
emptyRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1

With ws.[a1].CurrentRegion
lRow = .Row + .Rows.Count
.Cells(lRow, "C").Formula = "=IF(OFFSET(Klnr,ROW()-1,MATCH(""Opm"",Print_Titles,0)-1)<>"""",HYPERLINK(""#"" & CELL(""adres"",OFFSET(Klnr,ROW()-1,MATCH(""Opmerking"",Print_Titles,0)-1)),""bekijk""),"""")"
.Cells(lRow, "M").Formula = "=IF(OFFSET(Klnr,ROW()-1,MATCH(""Opm"",Print_Titles,0)-1)<>"""",HYPERLINK(""#"" & CELL(""adres"",OFFSET(Klnr,ROW()-1,MATCH(""Klnr"",Print_Titles,0)-1)),""terug""),"""")"
End With

'Export Forminput to worksheet
Cells(emptyRow, 4).Value = Txtsofi.Value
Cells(emptyRow, 5).Value = TxtVoorl.Value
Cells(emptyRow, 6).Value = Txtnaam.Value
Cells(emptyRow, 7).Value = Txtadres.Value
Cells(emptyRow, 8).Value = Txtnr.Value
Cells(emptyRow, 9).Value = TxtPostcode.Value
Cells(emptyRow, 10).Value = Txtwoonpl.Value
Cells(emptyRow, 11).Value = Txtdigid.Value
Cells(emptyRow, 12).Value = Txtdigiww.Value
Cells(emptyRow, 14).Value = TxtOpm.Value
End Sub

Sebastian H
01-24-2012, 12:36 PM
Hmm, why don't you just define the numbers (154,...) in their own column, and then use that in your formula, instead of reverse engineering the formula?

HV_L
01-24-2012, 03:40 PM
Cause I'm dealing with empty rows.. that's why I want to increase the value found with 1 and put that in A cloumn as a link to the corresponding folder.