Hey thanks for the replys
I have a solution - its kind of clunky - but it seems to work
Better idea's are always appreciated
I start by doing a find for a title with somethinglike this
TD is the activedocument
Msel is a Microsoft.Office.Interop.Word.Selection
MSel.Find.Text = Title_text
If MSel.Find.Execute() Then
MSel.MoveEnd(Microsoft.Office.Interop.Word.WdUnits.wdParagraph, 1)
MSel.Shrink() 'moves msel.start to begining of paragraph
MR = TD.Range(MSel.Start, ELoc) 'define range of bjtLine
If MR.Hyperlinks.Count > 0 Then
BjtItemLnk = MR.Hyperlinks(1).Address
End If
Call Discover(MR.Text)
MR = TD.Range(ELoc, ELoc) 'reset range to user selected location
MR.MoveEnd(Microsoft.Office.Interop.Word.WdUnits.wdParagraph, 2)
'extend to get document links
Else
MsgBox("Find Failed")
End If
If find worked, I then call discover to find the end of the section
Public Sub Discover(ByVal MStr As String)
'locates end of budget item to work on in BJT document
Dim Para As Microsoft.Office.Interop.Word.Paragraph
TxtLink = Microsoft.VisualBasic.Left(MStr, InStr(MStr, Chr(151)))
For Each Para In TD.Paragraphs
If InStr(Para.Range.Text, TxtLink) > 0 Then
FndBjt = True
End If
If FndBjt Then
Select Case True
Case Microsoft.VisualBasic.Left(Para.Range.Text, 11) =
"TEXT | HTML"
Call ProcPara(Para)
Exit For
Case Para.Range.Hyperlinks.Count > 1
Call ProcPara(Para)
Exit For
Case Microsoft.VisualBasic.Left(Para.Range.Text, 17) =
"Book moving later"
Call ProcPara(Para)
Exit For
Case Len(Para.Range.Text) < 5
Call ProcPara(Para)
Exit For
Case Para.Style.namelocal = "Title"
Exit Sub
Case Para.Style.namelocal = "Author"
Exit Sub
Case Para.Style.namelocal = "BjtDivider"
Exit Sub
... as many tests as necessay
End Select
End If
Next
End Sub
which then calls a procpara if appropriate end of section is discovered
Public Sub ProcPara(ByVal Para As Paragraph)
'processes each Hyperlink in end of budget item to check boxes
Dim HL As Hyperlink
LinkPara = Para 'LinkPara is the end of the section I will be
working with
For Each HL In LinkPara.Range.Hyperlinks
Call FndCB(HL)' this adds any hyperlink info to a hashtable
Next
Try
CheckBox1.Checked = InStr(LinkPara.Previous.Range.Text, "MOVED")
Catch ex As Exception
End Try
End Sub
When I want to process this section, adding new links, fixing old ones and
removing unwanted ones, I run this
Public Sub SaveToDoc()
'push info back to summary item
Dim HLMsg As String = "" 'replacement string for hypertext at end of
summary item
Dim FndMoved As Boolean = False
Try'set variable as to if the document has been reported to have moved
FndMoved = InStr(LinkPara.Previous.Range.Text, "MOVED") > 0
Catch ex As Exception
End Try
If CheckBox1.Checked Then
HLMsg = "MCTHLtext | MCTHLhtml"
If Not FndMoved Then
LinkPara.Previous.Range.Text =
Replace(LinkPara.Previous.Range.Text, vbCr, " MOVED" + vbCr)
End If
Else
If FndMoved Then
LinkPara.Previous.Range.Text =
Replace(LinkPara.Previous.Range.Text, "MOVED", "")
End If
HLMsg = "Book moving later"
End If
HLMsg += RetMsg(HT_HLA, Me.CheckedListBox1, 0) 'get replacement
names for string of checked items from checkedlistboxs
HLMsg += RetMsg(HT_HLA, CheckedListBox2, 0)
LinkPara.Range.Text = HLMsg + vbCrLf 'put string at end of budget item
LinkPara.Previous.Style = TD.Styles("krtText")
'find keywords and change to hyperlinks
Dim msg As String = ""
Dim ZZ() = Split(HLMsg, "|")
Dim x As Integer
Dim Indx As String = ""
Dim TS As String = BjtItemLnk
x = InStr(BjtItemLnk, "post_day=") + 9
Indx = Mid(BjtItemLnk, x, 8)
TS = Replace(TS, Indx, Format(Me.DateTimePicker1.Value, "yyyyMMdd"))
For x = 0 To UBound(ZZ)
Indx = Trim(Replace(ZZ(x), "MCTHL", ""))
msg += "-" + Indx + "-" + vbCrLf
Select Case True
Case Indx = "Book moving later"
Case Indx = "text"
AddHL(ZZ(x), Replace(TS, "format=krthtml&", ""))
Case Indx = "html"
AddHL(ZZ(x), TS)
Case Else
AddHL(ZZ(x), "")
End Select
Next
End Sub
Public Function RetMsg(ByVal HT As Hashtable, ByVal CLB As
CheckedListBox, ByVal offset As Integer) As String
'returns srtring of names related to checkboxes checked state
Dim X As Integer
RetMsg = ""
For X = 0 To CLB.Items.Count - 1
If CLB.GetItemChecked(X) Then
RetMsg += " | MCTHL" + CLB.Items(X)
End If
Next
End Function
this gets each name placed in the replacment string and adds a hyperlink
which hets its address from the hashtable and texttodisplay by removing part
of the variable name passed as ST
Public Sub AddHL(ByVal ST As String, ByVal HLt As String)
'adds Hyperlink to budget item replacing items in the replacement
string
Dim MSel As Microsoft.Office.Interop.Word.Selection
If Len(HLt) < 1 Then
HLt = HT_HLA.Item(Trim(Replace(ST, "MCTHL", "")))
End If
MSel = CLS07.thisapp.Selection 'should be an insertionIP
MSel.HomeKey()
MSel.Find.Forward = True
MSel.Find.Text = ST
If MSel.Find.Execute() Then
TD.Hyperlinks.Add(MSel.Range, HLt, "", "", UCase(Replace(ST,
"MCTHL", "")))
End If
End Sub
This parts sets the hashtable value for a chercklistboxitem to the link
provided by the editor in a textbox of the taskpane. I make two entries one
for pludal version of the checkedlistboxitem and the non plural version. This
was necessary because I set the checkedlistbox items itemcheck event to
toggle betweem unchecked. checked and indeterminate
.. The link info is the same for plual and non plural items
Public Sub HT_Text(ByVal Ci As String, ByVal AdrStr As String)
'set an item in the hashtable and duplicates the value to a plural
of the key
Dim Oi As String
Ci = Trim(Ci)
Oi = IIf(Microsoft.VisualBasic.Right(Ci, 1) = "s",
Microsoft.VisualBasic.Left(Ci, Len(Ci) - 1), Ci + "s")
HT_HLA.Item(Ci) = AdrStr
HT_HLA.Item(Oi) = AdrStr
End Sub