0
votes

I have a very strange problem with excel vba. I have narrowed the problem down and made this code to represent the problem as simply as possible.

   Sub Button1_Click()

   Button1_Click Macro
       Range("A1:B17").Select
       Selection.Copy
       Workbooks.Add
       ActiveSheet.Paste
       Application.CutCopyMode = False
   End Sub

On most computers I have no issue, but in the company we have two new laptops that give me the following error message on ActiveSheet.Paste row.

Run time error '1004'
Paste method of Worksheet class failed

I have tested this on both Windows 10 and 7, and on different computers. Only ones causing problems are the two new ones with Win10.

I saw this thread, and also tried the last option there about adding delays within the code:

Run Time Error '1004': Paste Method Of worksheet Class Failed error

Any suggestions how to solve this, and/or what is causing this issue?

-Rasmus-

1

1 Answers

0
votes

Do avoiding .Select.

And while pasting, do clearly determining the destination. Else it might be undefined because of the destination workbook was opened short time before.

Sub Button1_Click()

 ActiveSheet.Range("A1:B17").Copy
 Set newWB = Workbooks.Add
 newWB.Worksheets(1).Paste Destination:=newWB.Worksheets(1).Range("A1")
 Application.CutCopyMode = False

End Sub