#1
|
|||
|
|||
Error with exit macro
Hey guys,
I have this exit macro which has worked flawlessly in both Mac and Windows until yesterday when I used it in a Windows table (Mac works flawlessly in tables). The code stalls on the fourth line "Selection.Fields.Unlink." If I reverse the sequence of the third (ActiveDocument.Unprotect) and fourth lines, it works for the tables but stalls in the body of the text. I'm stumped. Suggestions? Code:
Sub UnlinkFieldsCensus() ' Unlink Fields Macro Selection.MoveRight Unit:=wdCharacter, Count:=1 Selection.MoveUp Unit:=wdParagraph, Count:=1, Extend:=wdExtend ActiveDocument.Unprotect Selection.Fields.Unlink Selection.MoveRight Unit:=wdCharacter, Count:=2 Dim Bookmark As Bookmark ActiveDocument.Bookmarks.ShowHidden = True If ActiveDocument.Bookmarks.Count >= 1 Then For Each Bookmark In ActiveDocument.Bookmarks Bookmark.Delete Next Bookmark End If End Sub |
#2
|
||||
|
||||
Try:
Code:
Sub UnlinkFieldsCensus() Dim Rng As Range, bHid As Boolean Set Rng = Selection.Paragraphs(1).Range With ActiveDocument .Unprotect Rng.Fields.Unlink With .Bookmarks bHid = .ShowHidden .ShowHidden = True While .Count > 0 .Item(1).Delete Wend .ShowHidden = bHid End With End With End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Still stalls
Hey Paul, with the code you gave me to try, both Mac and windows stall at "Rng.Fields.Unlink", but only if run in a table.
Thanks-Brent |
#4
|
||||
|
||||
After:
Set Rng = Selection.Paragraphs(1).Range insert: Rng.End = Rng.End - 1
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
Thanks Paul, works like a charm. Can you explain to me why the macro I posted would only stall in a Windows Table?
|
#6
|
||||
|
||||
Possibly it was stalling because 'Selection.MoveRight Unit:=wdCharacter, Count:=2' tried to move into or beyond the end-of-cell marker.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Help with Macro error | jar208 | Excel Programming | 2 | 12-06-2016 03:57 PM |
Pictures animated exit | abc3132 | PowerPoint | 0 | 02-26-2015 12:27 AM |
VBA error Content Control On Exit | jec1 | Word VBA | 5 | 08-16-2014 08:14 PM |
Drop-Downs: Run Macro on Exit | Andrew H | Word VBA | 15 | 11-16-2012 08:34 AM |
Is there an exit on close ? | mhdadmh | Word | 0 | 10-12-2006 04:28 PM |