Automating bookmarks?

B

Betina Y Andersen

I have a vba program that makes bookmarks in a word 2000 document, the code
gets executed via a VB program and no errors, but when I open the doc no
bookmarks have been made. I have tried to open Word and record a macro that
generates the code and it works fine, but it seem that when executed from my
vb(a) program it does absolutely nothin except saves the document. My code
below,
Thanks Betina

<code>
If antal > 0 Then
strType = WordObjJournal.ActiveDocument.Sentences(1).Text
If InStr(strType, "¤¤¤") Then
strGem = strType
strType = Mid(strType, 4, InStr(strType, "_") - 4)
WordObjJournal.Selection.WholeStory
nu = Format(Now, "MM-DD-YYYY_HH-MM-SS")
For i = 1 To antal
If i > 1 Then
WordObjJournal.Selection.WholeStory
WordObjJournal.Selection.start = pos2 + 1
End If
With WordObjJournal.Selection.Find
.ClearFormatting
.Text = "¤¤¤"
.Forward = True
.Execute
If .Found Then
Bm = "BM" & CStr(i)
ActiveDocument.Bookmarks.Add Range:=Selection.Range, Name:=Bm
WordObjJournal.Selection.Expand (wdLine)
strGem = WordObjJournal.Selection.Text
pos1 = WordObjJournal.Selection.End
'Information(wdFirstCharacterLineNumber)
WordObjJournal.Selection.EndKey
End If
.ClearFormatting
.Text = "¤¤¤"
.Forward = True
.Execute
If .Found Then
pos2 = (WordObjJournal.Selection.start) - 1
WordObjJournal.Selection.HomeKey
Else
pos2 = WordObjJournal.ActiveDocument.Content.End
End If
Set myRange = WordObjJournal.ActiveDocument.Range(start:=pos1,
End:=pos2).FormattedText
myRange.Select
Select Case UCase(strType)
Case "SELSKAB":
<code>
Case "AFDELING":
<code>
End Select
End With
Next
<code>
WordObjJournal.ActiveDocument.SaveAs FileName:=FilNavn
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top