Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 05-26-2018, 01:56 AM
THH4929 THH4929 is offline Replacing text held in all bookmarks Windows 10 Replacing text held in all bookmarks Office 2016
Novice
Replacing text held in all bookmarks
 
Join Date: May 2018
Posts: 3
THH4929 is on a distinguished road
Default Replacing text held in all bookmarks

Hello all,


I'm new to the whole VBA in word, and am struggling to resolve this issue!!!


What I am trying to achieve is to have a doc with various bookmarks, when a script is run, vba systematically goes through all bookmarks, requests user input via an inputbox, and then replaces the text with the user determined text.


This is what I have so far;


Code:
Sub UpdateBookmarks()

Dim bmInput As String

For Each bm In ActiveDocument.Bookmarks
    bmInput = InputBox("Please enter " & bm.Name)
    UpdateBM ActiveDocument, bm.Name, bmInput
Next

End Sub

Sub UpdateBM(ByRef bmDoc As Document, bmName As String, bmContent As String)
Dim bmRng As Word.Range
    Set bmRng = bmDoc.Bookmarks(bmName).Range
    bmRng.Text = bmContent
End Sub
However, when I run the code, it inserts the user input at the beginning of the text already present in the bookmark, rather than replacing it.


Please can anyone help??


Many thanks all
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Replacing text held in all bookmarks Tracking Stock Shares Held/Sold & Current Value CCITE140 Excel 1 11-30-2015 07:42 AM
Replacing the 2nd or 3rd instance of Text wdillon2 Word VBA 2 05-13-2015 10:21 PM
Replacing text held in all bookmarks Problem replacing text. piritzo Word 2 06-22-2013 12:50 AM
Replacing text held in all bookmarks Help with replacing text with wildcards sbatson5 Word 2 04-13-2012 03:49 AM
Replacing / editting text LisaC Word 0 02-25-2010 03:40 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:25 AM.


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