Quote:
Originally Posted by alshcover
How are StrOut variables defined as values in the bookmark code?
|
You do that by passing the StrOut value to the code you use to update the bookmark.
Since it seems you have multiple bookmarks to update, I've merged this thread and your previous one, so you can see how the two examples we have so far can be made to work with some common bookmark-updating code.
For the two examples so far we could use:
Code:
Private Sub cmdOK_Click()
Application.ScreenUpdating = False
Dim StrOut As String
StrOut = Format(dtDateFiled.Value, "MMMM DD, YYYY ")
Call UpdateBookmark("DateFiled", StrOut)
Select Case cboName.Value
Case "Bob": StrOut = "1"
Case "Cindy": StrOut = "2"
Case "Peter": StrOut = "3"
Case "Vanessa": StrOut = "4"
End Select
Call UpdateBookmark("Name", StrOut)
Application.ScreenUpdating = True
End Sub
You'll see how we now have two references to 'Call UpdateBookmark', with the bookmark name & content being included as arguments. Those two lines run the following sub, which handles the bookmark updating:
Code:
Sub UpdateBookmark(StrBkMk As String, StrTxt As String)
Dim BkMkRng As Range
With ActiveDocument
If .Bookmarks.Exists(StrBkMk) Then
Set BkMkRng = .Bookmarks(StrBkMk).Range
BkMkRng.Text = StrTxt
.Bookmarks.Add StrBkMk, BkMkRng
End If
End With
Set BkMkRng = Nothing
End Sub
Although I've referenced StrOut twice in the cmdOK_Click sub's call to the UpdateBookmark sub, just to show how the same variable can be re-used, the first instance could have been replaced with:
Call UpdateBookmark("DateFiled", Format(dtDateFiled.Value, "MMMM DD, YYYY "))