#1
|
|||
|
|||
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? |
#2
|
|||
|
|||
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 |
#3
|
|||
|
|||
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 ? |
#4
|
|||
|
|||
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. |
|
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 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 |