View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
keepITcool keepITcool is offline
external usenet poster
 
Posts: 2,253
Default Adding hyperlink after the existing data in the cell

Amit..

does this help?


Sub TextWithAppendedHyperlink()

Dim txt$, url$
Dim colorTxt, colorUrl&

url = "http://www.google.com"
colorUrl = ActiveWorkbook.Styles("Hyperlink").Font.Color

With ActiveCell

txt = .Value
If InStr(txt, vbLf & url) = 0 Then txt = txt & vbLf & url

colorTxt = .Font.Color
If IsNull(colorTxt) Then colorTxt = .Characters(1).Font.Color

.Hyperlinks.Add _
Anchor:=.Cells(1), _
Address:=url, _
TextToDisplay:=txt

With .Font
.Color = colorTxt
.Underline = False
End With
With .Characters(InStr(txt, vbLf & url) + 1, Len(url)).Font
.Color = colorUrl
.Underline = True
End With
End With

End Sub




--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


helpwithXL wrote :

Hi all,
Is it possible to create and add the hyperlink after the existing data
in the cell(that is, in the next line after the existing data in the
same cell). So what i'm trying to do is, to get an outlook email,
store email as .msg file in my folder and then add hyperlink to the
just stored file in a particular cell in my worksheet. I can do all
the things except for appending the hyperlink. As i create the
hyperlink and add it in the cell selected by user, all the data in
that cell is just overwritten by the hyperlink. So after this i only
have the hyperlink in the cell and all the data that was there in the
cell is lost. so is it possible to keep both , the existing data and
hyperlink added in the cell.
i tried reading the data of the cell into a variable before creating
and adding hyperling. then i added the hyperlink in the cell. then i
concatenated the data and hyperlink and then i made this
concatination as the value of cell. but with this process, all the
data is converted into the hyperlink, that is data that was there
before the hyperlink is also a part of hyperlink text now. so is it
possible to have normal text and hyperlink together in 1 cell.
my code is....

existingData = SelCells(j).Value
ActiveSheet.Hyperlinks.Add Anchor:=SelCells(j), _
Address:=FullPath, TextToDisplay:=Filename
hyperlinkString = SelCells(j).Value
SelCells(j).Value = existingData & vbCrLf & hyperlinkString


thanx for any help
amit