Share via

Basic VBA Code for Word using .Paste Won't Work

Anonymous
2016-03-26T07:52:50+00:00

Windows 10 Pro Version 1511 OS Build 10586.164

Office 365 Version 16.0.6741.2017

This problem showed up when I used code written for Word 2003. I hadn't used it since switching to Office 365. When I did run it, it would not work. This much simpler code demonstrates the problem.

Sub Test_Paste()

Dim doc As Document

Set doc = ActiveDocument

With Selection

.Copy

.Collapse Direction:=wdCollapseEnd

.TypeParagraph

.Paste

End With

End Sub

When I run it, I get this error:

Run-time error "4605"

This command is not available.

and it selects ".Paste"

Any help would be greatly appreciated.

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

9 answers

Sort by: Most helpful
  1. Anonymous
    2017-04-30T18:47:22+00:00

    Somewhere along the way, Word solved this problem by itself.

    Was this answer helpful?

    0 comments No comments
  2. Doug Robbins - MVP - Office Apps and Services 323.1K Reputation points MVP Volunteer Moderator
    2016-03-30T03:32:11+00:00

    I have no issues here with your original code in the 6741.2017 or now 6741.2021 version of Office.

    Perhaps there is an Add-in on your system that is causing the problem.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2016-03-29T15:18:25+00:00

    The purpose of the original script was to strip the text, which also had manually applied formatting , of a paragraph that was a Heading 1,or 2, or etc style, so that the paragraph could be set to Normal style and the text pasted back in with the manually applied formatting, but with the same indentation. I selected multiple paragraphs of a document, so even paragraphs that were not a Heading style were included. The manipulation had to be done paragraph by paragraph--two arrays were used--and it worked just fine when .Paste worked.

    The Range object won't work because even though the paragraph of the Heading is removed from the selection, the Range object is formatted as a Heading. When it is inserted, it is inserted as a Heading.

    The real solution is to get .Paste fixed--get Word fixed--because I can't use .Paste in any script. 

    I tried using the Repair option for 365, but each time it failed because, it said, there was an installation in process. Even after two restarts after Office was totally, according to the installer, reinstalled.

    I am not sure of how to proceed from here.

    Bill Martz

    Was this answer helpful?

    0 comments No comments
  4. Doug Robbins - MVP - Office Apps and Services 323.1K Reputation points MVP Volunteer Moderator
    2016-03-29T11:49:45+00:00

    Use:

    ActiveDocument.Bookmarks.Add "temp", Selection.Range

    Selection.Range.InsertAfter vbCr

    Selection.Collapse wdCollapseEnd

    Selection.FormattedText = ActiveDocument.Bookmarks("temp").Range.FormattedText

    ActiveDocument.Bookmarks("temp").Delete

    Was this answer helpful?

    0 comments No comments