It worked perfectly. The key thing I needed was the oCell and the
InsertAfter. I'm still trying to get more proficient with using Ranges.
Looks like I owe you a couple. Are you going to be traveling in April? ;-)
John... Visio MVP
"Shauna Kelly"
news:OOCkAyLYIHA.4808@TK2MSFTNGP05.phx.gbl...
> Hi John
>
> Something like this (add error checking to taste, and fix line breaks as
> needed):
>
> Sub ForJohnM()
>
> Dim oDoc As Word.Document
> Dim NameTable As Word.Table
> Dim RowNum As Long
> Dim UserName As String
> Dim BookMarkName As String
> Dim oCell As Word.Cell
> Dim rngHL As Word.Range
>
> 'Get a reference to the ActiveDocument.
> 'Avoid using 'ActiveDocument' more than once because
> 'Word is fickle
> Set oDoc = ActiveDocument
>
> Set NameTable = oDoc.Tables(1)
> RowNum = 1
> UserName = "John"
> BookMarkName = "Whatever"
>
> 'Get the cell to work with
> Set oCell = NameTable.Rows(RowNum).Cells(2)
>
> 'Add a tab stop with leader dots to the cell
> oCell.Range.ParagraphFormat.TabStops.Add Position:=InchesToPoints(5.4),
> Alignment:=wdAlignTabRight, Leader:=wdTabLeaderDots
>
> 'Get a range that does *not* include the end-of-cell marker
> Set rngHL = oCell.Range
> rngHL.MoveEnd Unit:=wdCharacter, Count:=-1
>
> 'Add a hyperlink to our range
> oDoc.Hyperlinks.Add Anchor:=rngHL, Address:="",
> TextToDisplay:=UserName, SubAddress:=BookMarkName, ScreenTip:="Click to
> view user"
>
> 'Add a tab at the very end of the cell, ie after the hyperlinked range
> oCell.Range.InsertAfter vbTab
>
>
> End Sub
>
>
> By the way, if this were mine and if there were lots of these cells, I'd
> create a separate paragraph style that includes the tab stop. You'll then
> be able to apply the style to the relevant cells. It will make it a lot
> faster to run the code and a lot easier to maintain.
>
>
> Hope this helps.
>
> Shauna Kelly. Microsoft MVP.
> http://www.shaunakelly.com/word
>
>
>
>
> "John Marshall, MVP"
> news:eb5MP2IYIHA.5784@TK2MSFTNGP03.phx.gbl...
>>I have a routine that populates a three column table (Ref #, Name, Page #)
>>that works fine. The cell with the Name is hyperlinked. I am now trying to
>>add a tab leader of dots to the end of the Name cell. I can add the tab
>>and set the tab leader to dots, but the tab is included in the hyperlink.
>>Any ideas how to correct this?
>>
>> Username = UserName & vbTab
>>
>> ActiveDocument.Hyperlinks.Add Anchor:=NameTable.Cells(RowNum,2).Range,
>> Address:="", TextToDisplay:=UserName, SubAddress:=BookMarkName, _
>> ScreenTip:="Click to view user"
>>
>> NameTable.Cell(RowNum,2).Range.ParagraphFormat.Tabstops.Add
>> Position:=InchesToPoints(5.4), Alignment:=wdAlignTabRight,
>> Leader:=wdTabLeaderDots
>>
>> Any alternate suggestions would also be appreciated.
>>
>> John... Visio MVP
>>
>
>