View Single Post
 
Old 06-19-2023, 05:06 AM
gmaxey gmaxey is offline Windows 10 Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

You posted this code originally and claimed that is works:


Code:
Sub ladate()
Dim date1 As Date
date1 = Now()
BookChange "DatePP, format(date1, "dd/mm/yy")
End Sub

Well, it is impossible for that code to work because a) if you paste it in Word VBA project it will not compile and b) it doesn't compile because there is no such method in the Word object model called "BookChange"


Now perhaps your code is attempting to call another procedure named "BookChange" and you neglected to post that procedure. Even so, your procedure still won't compile as your have the call improperly formatted.

Code:
Sub ladate()
Dim date1 As Date
date1 = Now()
  BookChange "DatePP", Format(date1, "dd/mm/yy")
End Sub

Sub BookChange(strBMName As String, strDate As String)
Dim oRng As Range
  Set oRng = ActiveDocument.Bookmarks(strBMName).Range
  oRng.Text = strDate
  ActiveDocument.Bookmarks.Add strBMName, oRng
lbl_Exit:
  Exit Sub
End Sub


Now you have a procedure where you can pass arguments 1) Bookmark name and 2) Value to a custom procedure that functions as a method "BookChange"


oRng is a range yes. You set it parameters (i.e. start and end points) to the same range as the bookmark. Then assign a text string range.text property. This destroys the bookmark, so the last step is to recreate the bookmark around the defined range.


Hope this helps.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote