L
LEU
I have the following macro that saves the data from my form to my document.
Not all of my documents will have a bookmark ‘bknbr4’. How do I write it to
say the following:
If ‘bknbr4’ exist in ActiveDocument then
Set oRng = oBMs("bknbr4").Range
oRng.Text = Text1.Text
oBMs.Add "bknbr4", oRng
Else
Do nothing
End If
Option Explicit
Private oBMs As Bookmarks
Private oRng As Word.Range
Dim oFF As FormFields
Private Sub cmdOK_Click()
Set oFF = ActiveDocument.FormFields
Set oRng = oBMs("bknbr").Range
oRng.Text = Text1.Text
oBMs.Add "bknbr", oRng
Set oRng = oBMs("bknbr2").Range
oRng.Text = Text1.Text
oBMs.Add "bknbr2", oRng
Set oRng = oBMs("bknbr3").Range
oRng.Text = Text1.Text
oBMs.Add "bknbr3", oRng
Set oRng = oBMs("bknbr4").Range
oRng.Text = Text1.Text
oBMs.Add "bknbr4", oRng
ActiveDocument.Saved = True
Me.Hide
End Sub
Not all of my documents will have a bookmark ‘bknbr4’. How do I write it to
say the following:
If ‘bknbr4’ exist in ActiveDocument then
Set oRng = oBMs("bknbr4").Range
oRng.Text = Text1.Text
oBMs.Add "bknbr4", oRng
Else
Do nothing
End If
Option Explicit
Private oBMs As Bookmarks
Private oRng As Word.Range
Dim oFF As FormFields
Private Sub cmdOK_Click()
Set oFF = ActiveDocument.FormFields
Set oRng = oBMs("bknbr").Range
oRng.Text = Text1.Text
oBMs.Add "bknbr", oRng
Set oRng = oBMs("bknbr2").Range
oRng.Text = Text1.Text
oBMs.Add "bknbr2", oRng
Set oRng = oBMs("bknbr3").Range
oRng.Text = Text1.Text
oBMs.Add "bknbr3", oRng
Set oRng = oBMs("bknbr4").Range
oRng.Text = Text1.Text
oBMs.Add "bknbr4", oRng
ActiveDocument.Saved = True
Me.Hide
End Sub