Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-16-2023, 07:33 AM
leurne leurne is offline bookmark with bookchange Windows 10 bookmark with bookchange Office 2021
Novice
bookmark with bookchange
 
Join Date: Jun 2023
Posts: 9
leurne is on a distinguished road
Default bookmark with bookchange


hello, i have a bookmark called DatePP
i would like to make a macro in order to update manually with the current date.
(i dont want to have a automatic date because we can't have some tracking of the update...)

so i wrote:

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


it's working however if i want to update a second time my date.... The bookmark DatePP disappear...

Do you have an idea how to solve it?
Reply With Quote
  #2  
Old 06-16-2023, 01:45 PM
gmaxey gmaxey is offline bookmark with bookchange Windows 10 bookmark with bookchange Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

I can't image how it is working as there is no such method in the Word Object model named "BookChange"


Code:
Sub ScratchMacro()
'A basic Word Macro coded by Gregory K. Maxey
Dim oRng As Range
  Set oRng = ActiveDocument.Bookmarks("DatePP").Range
  oRng.Text = Format(Now, "MMMM dd, yyyy")
  ActiveDocument.Bookmarks.Add "DatePP", oRng
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 06-18-2023, 10:42 PM
leurne leurne is offline bookmark with bookchange Windows 10 bookmark with bookchange Office 2021
Novice
bookmark with bookchange
 
Join Date: Jun 2023
Posts: 9
leurne is on a distinguished road
Default

ooooh! it's working! that's perfect

What do you mean "such method in the word object"?

So if i understand well
you created a variable call "oRng" as a range (range in order to set the bookmark inside? it will define an area instead of a value isn't it?)
Then you set the oRng as datepp
and you insert in the date inside orng with oRng.Text = format ...

I dont understand the activedocument.bookmarks.add "datepp", orng = is it to add back the bookrmarks ?
Reply With Quote
  #4  
Old 06-19-2023, 05:06 AM
gmaxey gmaxey is offline bookmark with bookchange Windows 10 bookmark with bookchange Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
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
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
REf Fields show Bookmark whole cell when Bookmark is created by code. pmcpowell Word VBA 2 11-16-2019 07:05 PM
Inserting a bookmark DavidTheToad Word VBA 1 06-04-2017 05:45 PM
Find Bookmark, move to bookmark, execute code, repeat raymm3852 Word VBA 10 04-15-2016 06:21 PM
bookmark with bookchange Bookmark Not Showing Bookmark RegAudit Word 6 03-16-2015 11:08 PM
vba to go to next bookmark megatronixs Word VBA 2 06-08-2014 09:53 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:52 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft