To edit a MS Word document while macro is running RRS feed

  • Question

  • Hello Experts,

    My document contains many fields (for example 1 to 10). I have created a macro that runs through each field. When I go to each field by running the macro, it displays some message (for example, the field name itself).

    When the macro is running, I want to pause the macro at field no. 4, edit some text in the word document, add a comment, and then resume the running macro from field no.5.

    (By default, when the macro is runnning,  the word document is locked and I am not able to edit anything)

    I have given a button in the toolbar that allows users to run the macro. Pls suggest some solution for this.




    Monday, June 27, 2011 4:34 PM

All replies

  • In your macro, use code like this after you process field 4:

    Selection.HomeKey wdStory
    With Selection.Find
        .Text = "This is the text to replace"  'Assuming you have a standard text that you edit
        .Replacement.Text = InputBox("Replacement text?", , "This is the new text")
        .Execute Replace:=wdReplaceOne
    End With

    Selection.Comments.Add Range:=Selection.Range
    Selection.TypeText Text:=InputBox("Comment text?", , "This is my comment")

    HTH, Bernie
    Monday, June 27, 2011 5:47 PM