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?
 

Some videos you may like

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
35,503
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
The Range.Copy method will only accept an Excel range as the destination argument.
 

klutch

New Member
Joined
Jun 7, 2018
Messages
38
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.
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
35,503
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
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.
 

klutch

New Member
Joined
Jun 7, 2018
Messages
38
Okay thanks! I started vba last week so I am sure I am being redundant
 

Watch MrExcel Video

Forum statistics

Threads
1,108,974
Messages
5,525,990
Members
409,673
Latest member
Riseee

This Week's Hot Topics

Top