none
Document not got the focus RRS feed

  • Question

  • We have a macro which, with one document already open, opens a second document, gets some text from it, closes the second document and then pastes that text into the original document. The code is something like this

      sub mymacro()

    Dim mydoc As Document,mystart as long,myend as long
      Set mydoc = ActiveDocument

      Documents.Open FileName:="otherdoc.docx", ReadOnly:=true
      Documents("otherdoc.docx").Activate
      'find some text from otherdoc, copy the text we want then close otherdoc

      Selection.Copy
      ActiveDocument.Close

    'reactivate the original document

      mydoc.Activate
    'paste the information into the original document

      mystart=selection.range.start

       Selection.Paste
      myend = Selection.Range.End
      ActiveDocument.Range(mystart, myend).Select

    end sub

    Everything works exactly as we want with one exception.

    After the macro has finished we have to click back into the original document to do some more editing. It is as if the original document, though active, does not have the focus; so when you type, nothing happens.

    Any suggestions anyone?

    Wednesday, August 7, 2013 12:50 PM

Answers