Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-30-2014, 11:27 AM
ptmuldoon ptmuldoon is offline Looping/Update BookMark Crashes. Windows 7 64bit Looping/Update BookMark Crashes. Office 2013
Advanced Beginner
Looping/Update BookMark Crashes.
 
Join Date: Sep 2014
Posts: 93
ptmuldoon is on a distinguished road
Default Looping/Update BookMark Crashes.

I'm working to create a small script that will 'reset' my bookmarks back to default comments. However, Word keeps crashing each time it attempts to run and I can't seem to figure out why.



This is the sample code, I'm currently working with.
Code:
Sub ResetBookMarks()
    Dim BMName, DefaultComment As String
    Dim oRng As Word.Range
    
    DefaultComment = "XXXXXX"

    For Each Bmk In ActiveDocument.Bookmarks    
        'MsgBox Bmk.Name
        BMName = Bmk.Name
        Set oRng = ActiveDocument.Bookmarks(Bmk.Name).Range
        oRng.Text = ActiveDocument.Bookmarks(Bmk.Name).Range.Text & "Some text here."
        ActiveDocument.Bookmarks.Add BMName, oRng
    Next
    
    ActiveDocument.Bookmarks.ShowHidden = True
    ActiveWindow.View.ShowBookmarks = False
End Sub
FYI.. I'm mainly learned the above so far from Greg Maxey's MVP help here.
http://gregmaxey.com/word_tip_pages/..._bookmark.html
Reply With Quote
  #2  
Old 12-31-2014, 07:19 AM
gmaxey gmaxey is offline Looping/Update BookMark Crashes. Windows 7 32bit Looping/Update BookMark Crashes. Office 2010 (Version 14.0)
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

Try something like:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim lngIndex As Long
Dim oBM As Bookmark
Dim oRng As Range
Dim strName As String
For lngIndex = ActiveDocument.Bookmarks.Count To 1 Step -1
Set oBM = ActiveDocument.Bookmarks(lngIndex)
strName = oBM.Name
Set oRng = oBM.Range
oRng.Text = oBM.Name
ActiveDocument.Bookmarks.Add strName, oRng
Next
End Sub
__________________
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
Looping/Update BookMark Crashes. Need help on macro for looping kilosub Word VBA 31 07-27-2011 01:37 PM
Looping Question Steve B PowerPoint 0 01-19-2011 10:44 AM
Looping video tomasball PowerPoint 0 10-30-2010 02:38 PM
Unbreakable looping Dixon Outlook 0 09-23-2009 02:10 PM
Looping though Custom Properties in VBA suekay Misc 0 05-19-2006 06:10 AM

Other Forums: Access Forums

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


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