thandel
asked on
Recreate bookmark
I have a form that user complete and within that form I have a book mark that after the document is opened VBA nicely fills in the computer name so I can determine which/who completed the form.
All is working fine but if I have to edit the form when its opened the macro runs as it should and places my computer name correctly in the bookmark.
The issue is that when it fills in the bookmark with the computer name the books mark is lost which causes other issues for me not related to this question.
Is there a way to either maintain the bookmark name or recreate with a macro?
Here is my document_open code: (document is protected, no password)
All is working fine but if I have to edit the form when its opened the macro runs as it should and places my computer name correctly in the bookmark.
The issue is that when it fills in the bookmark with the computer name the books mark is lost which causes other issues for me not related to this question.
Is there a way to either maintain the bookmark name or recreate with a macro?
Here is my document_open code: (document is protected, no password)
Sub Document_Open()
On Error GoTo ErrHandler
ActiveDocument.Unprotect
ActiveDocument.Bookmarks("computer").Range = Environ$("computername")
ActiveDocument.Protect wdAllowOnlyFormFields
With ActiveWindow
.DisplayHorizontalScrollBar = True
.DisplayVerticalScrollBar = True
.DisplayLeftScrollBar = False
.StyleAreaWidth = InchesToPoints(0)
.DisplayVerticalRuler = True
.DisplayRightRuler = False
.DisplayScreenTips = False
With .View
.ShowBookmarks = True
.FieldShading = wdFieldShadingAlways
End With
End With
'MsgBox "Please complete form on computer and email to:" & vbCr & vbCr & _
"bla@bla.com" & vbCr & vbCr, vbOKOnly, "Order Submission"
Application.DisplayStatusBar = True
Application.ShowWindowsInTaskbar = True
Application.ShowStartupDialog = False
ActiveWindow.EnvelopeVisible = True
ErrHandler:
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You use it in the standard way:
FillBookMark doc.BookMarks("Computer"), ""
where doc is an object variable for the target document. If you don't have a separate variable, then probably ActiveDocument will do. FillBookMark ActiveDocument.BookMarks("Computer"), ""
ASKER
So should FillBookMark be a function or sub routine?
As you will see, it's a Sub, as opposed to a Function which must be used if a return value is needed.
Copy it into your code module. To use it in your code, you would need to change the line:
Copy it into your code module. To use it in your code, you would need to change the line:
ActiveDocument.Bookmarks("computer").Range = Environ$("computername")
to
FillBookmark ActiveDocument.Bookmarks("computer"), Environ$("computername")
ASKER
Ah now I see, thanks.
ASKER