Thread: [Solved] VBA Code apply draft
View Single Post
 
Old 02-21-2017, 04:55 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,138
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

It certainly does, because it appears to be calling a procedure WriteToBookmarkRange that doesn't exist, and the macro as written also has no idea what cboYourName.Value is.

If you want to write text to a bookmark, you could call the FillBM sub from my web site:
Code:
Public Sub FillBM(strBMName As String, strValue As String)
'Graham Mayor - http://www.gmayor.com
Dim oRng As Range
    With ActiveDocument
        On Error GoTo lbl_Exit
        Set oRng = .Bookmarks(strBMName).Range
        oRng.Text = strValue
        oRng.Bookmarks.Add strBMName
    End With
lbl_Exit:
    Set oRng = Nothing
    Exit Sub
End Sub
This will write the value to the named bookmark (here "Draft"), assuming that bookmark exists also. If not it does nothing. e.g.
Code:
If .Bookmarks.Exists("Status") Then FillBM "Draft", Environ("USERNAME")
This inserts the user's name at the bookmark, which I guessed may be what the missing value was all about.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote