Run-Time error '1004' "Copy Method of Range Class Failed"

klutch

New Member
Joined
Jun 7, 2018
Messages
38
I am running a code that will copy and paste a piece of data into a specific location of a selected file. This is what I have so far
Code:
Sub CopyandPaste()
Dim myfile
myfile = Application.GetOpenFilename(, , "Browse for Document")
Dim wdapp As Word.Application
Set wdapp = CreateObject("Word.Application")
wdapp.Visible = True
Dim wddoc As Word.document
Set wddoc = wdapp.Documents.Open(myfile)
If Range("L2") <= 30 And Range("L2") >= 20 Then Range("j2").Copy myfile
If Range("L2") <= 19 And Range("L2") >= 0 Then Range("J2").Copy myfile
If Range("L2") <= -1 And Range("L2") >= -30 Then Range("j2").Copy myfile
End Sub
The debugger identified the "myfile" after the copy as the cause for this. Does it want me to specify where in the document to put it? if so how do I do that?
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
The Range.Copy method will only accept an Excel range as the destination argument.
 
Upvote 0
The Range.Copy method will only accept an Excel range as the destination argument.
what method will work for this then?
I am thinking
Code:
  If Range("L2") <= 30 And Range("L2") >= 20 Then Range("j2").Copy range("s2")
If Range("L2") <= 19 And Range("L2") >= 0 Then Range("J2").Copy range("s2")
If Range("L2") <= -1 And Range("L2") >= -30 Then Range("j2").Copy Range("s2")
select.range("s2") 
selection.copy 
open.myfile 
select.myfile
selection.paste

This is just a guess but would you know the exact method to get it to paste into my file? also looking for advice to paste it in a table at the end of the document.
 
Upvote 0
There isn't much point in copying one range to another just to then copy that second range to the clipboard. You can just copy the first range to the clipboard. I confess I don't follow your code as you seem to copy the same range regardless of the conditions.

I don't do Word, but I would assume you can simply paste to the selection, or a specified part of the document. You'd be better off posting in the General Discussion forum for that.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top