A family of Microsoft word processing software products for creating web, email, and print documents.
I have 6741.2021 and have added no add-ins. As I say, something is broken somewhere. Thanks for all your input.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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.
A family of Microsoft word processing software products for creating web, email, and print documents.
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.
I have 6741.2021 and have added no add-ins. As I say, something is broken somewhere. Thanks for all your input.
Hi Doug,
Thank you very much for your reply. I have always had something selected as I have tried to solve this. The original version of this code used a cut, and I had error handling in case of the empty selection issue. So, even after adding your suggested lines, the problem still occurs.
Since it worked with your system, that says to me I have something broken in my setup. The question now is to figure out what and how to fix it.
If you have any suggestions about that, I am all ears.
Thanks,
Bill Martz
Thanks, Doug, for your suggestion.
First, something is broken somewhere: I cannot use Paste in any way. I removed and reinstalled Office 365 four times without eliminating the problem.
I tried this code, which I expected would do the actual replacement I want:
Sub Test_Paste2()
Dim rng As Range
Selection.End = Selection.End - 1
Set rng = Selection.Range
Selection.Style = ActiveDocument.Styles("Normal")
rng.InsertAfter & rng.FormattedText
End Sub
But the line, "rng.InsertAfter & rng.FormattedText" turns red as soon as I type it. I want to put the formatted text back into the same location. I put vbCr back in, and, as expected, it pastes the text, but unformatted, into the new line.
Bill
Use the following:
Dim rng As Range
Set rng = Selection.Range
rng.InsertAfter vbCr & rng.FormattedText
or
Selection.Range.InsertAfter vbCr & Selection.Range.FormattedText
or
With Selection.Range
.InsertAfter vbCr & .FormattedText
End With
It doesn't matter then if there is nothing selected.
It works fine as long as the selection contains something.
The full text of the error message "The method or property is not available because no text is selected", but here in the same version of Word, it is the Copy command that throws the error.
To prevent the error from occurring, using the following construction
With Selection
If .Type <> wdSelectionIP Then
.Copy
.Collapse Direction:=wdCollapseEnd
.TypeParagraph
.Paste
End If
End With