Consulting

Results 1 to 12 of 12

Thread: Undo AutoFormat w/DocumentMap = True

  1. #1
    VBAX Regular
    Joined
    Jan 2006
    Posts
    56
    Location

    Undo AutoFormat w/DocumentMap = True

    Hi All,
    When I open an existing Document with the DocumentMap turned off and I turn it on by explicitly selecting it under the "View" menu option, I then see "Undo AutoFormat" under the "Edit" menu option. What VB command does "Undo AutoFormat" correspond to in this case ? I tried to Record a macro to find out the command, but when the Record macro toolbar is up, the "Undo AutoFormat" option under "Edit" is greyed-out.


    Any tips or ideas would be greatly appreciated! Thanks!!

    Ed

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Not sure but this might help:
    [VBA]
    ActiveWindow.DocumentMap = True
    ActiveWindow.DocumentMap = False
    [/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I think I misunderstood your question...
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I think undo is a tough one in VBA
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  5. #5
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Huh? There is an Undo.[vba]Selection.TypeText Text:="Hello World"
    ActiveDocument.Undo[/vba]would type "Hello World", then remove that text.
    [vba]Sub TestUndo()
    ActiveDocument.Tables.Add Range:=Selection.Range, _
    numrows:=3, numcolumns:=5
    Selection.Tables(1).Cell(2, 2).Range.Text = _
    "This is text in cell (2, 2)."
    ActiveDocument.Undo
    ActiveDocument.Undo
    End Sub[/vba]would make a table of 3 rows / 5 cols; put text into Cell( 2,2); then undo the text insertion; then undo the table insertion...leaving it exactly the way it was - no table, no text.

  6. #6
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Oh, and of course there is a:[vba]ActiveDocument.Redo[/vba]

  7. #7
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Thanks Gerry.......
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  8. #8
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    This however, is not all that relevant to the original post.

    Could you restate exactly what you want to do? The Document Map is a sort of autoformat thingie...

  9. #9
    VBAX Regular
    Joined
    Jan 2006
    Posts
    56
    Location

    What I am trying to do

    Hi,
    What I am trying to do is programmatically undo the AutoFormat-ing that is done when the property DocumentMap = True for a given document.

    I'm thinking that the following code snippet would do the trick:
    [vba]
    If (ActiveDocument.ActiveWindow.DocumentMap = True) Then
    ActiveDocument.Undo
    End If
    [/vba]
    Is the last line in the above If-block the correct statement to issue to Undo AutoFormat ?

    And a related question: I understand that Command-Z pressed repeatedly, will go to the 3 most recently edited locations in the ActiveDocument. What object (ie. collection class I guess) are these locations stored in ? Can I get access to this object in VB ? And is the limit of 3 hard-coded, or can I change it?


    Thanks!


    Ed

  10. #10
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    The Document Map is a strange beast. Invoking it causes AutoFormat. It is, in fact, an AutoFormat process. I found this out from macropod over at Tek-Tips - who knows a thing or two.

    I am not sure it is in fact possible to truly "undo" the AutoFormat of Document Map.

    Very good question re: the undo "collection"...I can't find it...yet there must be something!

  11. #11
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    What do you want to do?

    Viewing the Document Map *may* trigger an AutoFormat (over which I don't think you have any control) and you can Undo it of you like, but if you do then you will lose the content of the map. Or you can clear the undo stack so that it can't be undone.

    You can do Shift+F5 to goback to the last three edit points in a document but AFAIK you have no programmatic access to the undo stack.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  12. #12
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    And I will have to agree with Tony. I have been seriously looking and I can not find any access to the undo stack at all. You can action it, but that is all.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •