• Problems with macro that copies terms to another document

    Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » Problems with macro that copies terms to another document

    Author
    Topic
    #494410

    Hi, folks,

    I’ve been using this macro to make my editing conventions list since 2004 (I got it fro the Editorium.)

    Code:
    Sub GetThat2()
         Selection.Copy
         WordBasic.NextWindow
         Selection.PasteAndFormat (wdPasteDefault)
         Selection.TypeParagraph
         WordBasic.NextWindow
         Selection.MoveRight Unit:=wdCharacter, Count:=1
    
    End Sub
    

    Today, my client did not allow me to load my macros onto its computer. So I recorded a macro like this:

    Sub GetTerm2()

    ‘ GetTerm2 Macro


    Application.Run MacroName:=”Editing.WordMacros.EditCopy”
    Windows(“conventions doc”).Activate
    Selection.PasteAndFormat (wdPasteDefault)
    Selection.TypeParagraph
    Windows(“Main doc”).Activate
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    End Sub

    I don’t want the file names in the code because the macros needs to work on many different files–like the old one does. I tried replacing the Windows….Activate lines with “ActiveWindow.Next.Activate” and “ActiveWindow.Previous.Activate” (which I found on a VBA code snippets site), but the resulting macro doesn’t work. I haven’t put”WordBasic.NextWindow” in there because I know from experience that Word Basic commands sometimes cause Word to hang and it’s pretty clear that MS is moving away from them. Can someone tell me how to fix the code, tell me how to keep the macro recorder form putting in file names, or take pity on me and give me working code?

    Cheers

    Viewing 4 reply threads
    Author
    Replies
    • #1449925

      This works for me:

      Code:
      Sub Demo()
      With Application
        .ScreenUpdating = False
        Selection.Copy
        With .ActiveWindow.Next.Selection
          .PasteAndFormat (wdPasteDefault)
          .TypeParagraph
        End With
        .ScreenUpdating = True
      End With
      End Sub

      I’m not sure what the issue is re “my client did not allow me to load my macros onto its computer”, since the end result is no different than typing the same macro from scratch. Perhaps they’d be less reticent if you stored your macros in plain text files and simply copied the ones you needed from there?

      Cheers,
      Paul Edstein
      [Fmr MS MVP - Word]

    • #1449938

      Thanks, Paul. The client won’t allow anyone to insert a thumb drive or other device. Their security software doesn’t even like it when someone charges their phone via a USB port. They are my only client that is so strict. A few insist on running antivirus software on the thumb drive, but most give me permission to install the add-ons—with my promise to remove them when the job is done.

      The really interesting thing is how different yesterday’s recorded macro is from the one recorded in 2004. I recall re-recording several macros in 2007 using W2007. They were the same as those recorded using W2003 (and used Word basic commands).

      Just by reading, I see that your macro does the first part of what my recorded macro does. The second part—to return to the first document with the cursor position just past the previously selected text. I’ll try to add that later today.

      Thanks very much,
      Pam

    • #1449975

      Try:

      Code:
      Sub Demo()
      With Application
        .ScreenUpdating = False
        Selection.Copy
        With .ActiveWindow.Next.Selection
          .PasteAndFormat (wdPasteDefault)
          .TypeParagraph
        End With
        Selection.Collapse wdCollapseEnd
        .ScreenUpdating = True
      End With
      End Sub

      Cheers,
      Paul Edstein
      [Fmr MS MVP - Word]

    • #1450119

      Hi, Paul,

      With your code and with the code I tried to modify, I’m getting an “Object variable or block variable not set error” message.

      Pam

    • #1450120

      The only time I get an error is if nothing is selected. Using ‘On Error Resume Next’ before ‘Selection.Copy’ would take care of that, though you might then end up with whatever else is in the clipboard being pasted. Better would be:

      Code:
      Sub Demo()
      With Application
        .ScreenUpdating = False
        On Error GoTo ErrExit
        Selection.Copy
        With .ActiveWindow.Next.Selection
          .PasteAndFormat (wdPasteDefault)
          .TypeParagraph
        End With
        Selection.Collapse wdCollapseEnd
      ErrExit:
        .ScreenUpdating = True
      End With
      End Sub

      Cheers,
      Paul Edstein
      [Fmr MS MVP - Word]

    Viewing 4 reply threads
    Reply To: Problems with macro that copies terms to another document

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: