#1
|
||||
|
||||
replacing text in a variable
I was really trying to do this myself, but alas I got stuck.
I want to insert a bookmark at the present location with the name of the selected text. so we have selText=selection.text But of course, we cannot have any spaces in a BM name. I also need the current page number as part of the BM name so we have selText=selection.text So we need to turn "my selected text" into "01_my_selected_text" The rest I think I can handle. Thank you and have a good day! Susan Flamingo Update Edit: Update Edit: I was able to do this (hurray for me!! Dim SelectedText As String Dim BMN As String Dim pgNo As Integer Dim newPN As String SelectedText = Selection.Text pgNo = Selection.Range.Information(wdActiveEndPageNumber) newPN = CStr(pgNo) BMN = Replace(SelectedText, " ", "_") 'BMN = newPN & "_" & BMN With ActiveDocument.Bookmarks .Add Range:=Selection.Range, Name:="pg" & newPN & "_" & BMN End With Is this high quality code? |
#2
|
|||
|
|||
Hi Susan,
I am no one to judge the quality of code (but Andrew is, IMO). Keep in mind that the concept of "page" is a very slippery / nebulous concept when working in Word. I have no clue why you want it part of a bookmark name. Word Doesn't Know What a Page Is by Daiya Mitchell, MVP |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Pasting in text, selecting that text, replacing words within that text but adding numbers too | ctviggen | Word VBA | 0 | 03-25-2023 11:56 AM |
I am automating word using vba. Need Help replacing paragraph with variable information | Puneet Singh | Word VBA | 18 | 02-08-2022 10:48 PM |
ord vba replace the variable text with variable images to make offer products with images | tanzinim | Word VBA | 4 | 12-30-2015 01:40 PM |
Replacing the 2nd or 3rd instance of Text | wdillon2 | Word VBA | 2 | 05-13-2015 10:21 PM |
Replacing / editting text | LisaC | Word | 0 | 02-25-2010 03:40 AM |