Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-19-2016, 03:23 AM
vince692 vince692 is offline How to insert text before bookmark ? Windows 7 64bit How to insert text before bookmark ? Office 2010 32bit
Novice
How to insert text before bookmark ?
 
Join Date: May 2016
Posts: 22
vince692 is on a distinguished road
Default How to insert text before bookmark ?

Hi,

Here is what i found :
Code:
ActiveDocument.Bookmarks("MybookmarkName").Range.InsertBefore ("toto")
"toto" is inserted before (at the start of) my bookmark.
The function i am looking for is to write before the bookmark (meaning out of bookmark range).

Any hints ?
BR,


Vincent
Reply With Quote
  #2  
Old 05-19-2016, 03:48 AM
gmayor's Avatar
gmayor gmayor is offline How to insert text before bookmark ? Windows 10 How to insert text before bookmark ? Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

It is more useful to write IN the bookmark, which enables the content to be changed, for which you can look at the FillBM function on my web site.

The code you quote
Code:
ActiveDocument.Bookmarks("MybookmarkName").Range.InsertBefore "toto"
will write before the named bookmark 'MybookmarkName', the text 'toto' What other hints do you require?
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 05-19-2016, 03:55 AM
vince692 vince692 is offline How to insert text before bookmark ? Windows 7 64bit How to insert text before bookmark ? Office 2010 32bit
Novice
How to insert text before bookmark ?
 
Join Date: May 2016
Posts: 22
vince692 is on a distinguished road
Default

Indeed it is usefull to write IN the bookmark but it is not what i am seeking for today.

I want to add a text BEFORE the bookmark, no link between them.
Any hints ?
Reply With Quote
  #4  
Old 05-19-2016, 04:04 AM
gmayor's Avatar
gmayor gmayor is offline How to insert text before bookmark ? Windows 10 How to insert text before bookmark ? Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

As I asked, what hints do you want? The code you posted will do that. I merely removed the brackets which were superfluous.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #5  
Old 05-19-2016, 04:34 AM
vince692 vince692 is offline How to insert text before bookmark ? Windows 7 64bit How to insert text before bookmark ? Office 2010 32bit
Novice
How to insert text before bookmark ?
 
Join Date: May 2016
Posts: 22
vince692 is on a distinguished road
Default

When you call my code here is the result :

[totoMyTextInsideMyBookmark]

I want :

toto[MyTextInsideMyBookmark]

I hope my problem appears now
Reply With Quote
  #6  
Old 05-19-2016, 05:29 AM
gmayor's Avatar
gmayor gmayor is offline How to insert text before bookmark ? Windows 10 How to insert text before bookmark ? Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

OK I see what you mean. The following should address it.

Code:
Dim oRng As Range
Dim oOriginal As Range
    Set oOriginal = ActiveDocument.Bookmarks("MybookmarkName").Range
    Set oRng = ActiveDocument.Bookmarks("MybookmarkName").Range
    oRng.Collapse 1
    oRng.Text = "toto"
    oOriginal.start = oRng.End
    oOriginal.Bookmarks.Add "MybookmarkName"
or alternatively
Code:
Dim oRng As Range
Dim oOriginal As Range
Dim sText As String: sText = "toto"
    Set oRng = ActiveDocument.Bookmarks("MybookmarkName").Range
    oRng.InsertBefore sText
    oRng.MoveStart Count:=Len(sText)
    oRng.Bookmarks.Add "MybookmarkName"
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #7  
Old 05-19-2016, 05:44 AM
vince692 vince692 is offline How to insert text before bookmark ? Windows 7 64bit How to insert text before bookmark ? Office 2010 32bit
Novice
How to insert text before bookmark ?
 
Join Date: May 2016
Posts: 22
vince692 is on a distinguished road
Default

OMFG you are too strong. Your help is very much apreciated
This topic is solved.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Replicating Insert Hyperlink-Bookmark function Marrick13 Word VBA 0 02-05-2016 01:27 PM
How to insert text before bookmark ? Is there anyway I can insert an easy bookmark in word? BayhDole Word 2 07-21-2015 08:43 PM
How to insert text before bookmark ? Open header to insert text into bookmark Amapola188 Word VBA 3 07-12-2012 05:16 PM
How to insert text before bookmark ? Word 2003 - IncludeText Does Not Include Bookmark Text if in a Form Text Control skarden Word 1 12-12-2011 10:39 PM
How to insert text before bookmark ? VBA to insert Bookmark rockwellsba Word VBA 2 05-31-2011 01:07 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:11 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