Solved

Application defined error

Posted on 2011-03-16
9
205 Views
Last Modified: 2012-05-11
Hi,

I have the below code and it errors on

 ActiveSheet.Paste


Application or object defined error.

Can anyone see why this is?

Thanks
Seamus
Windows("balances.xls").Activate
    Columns("A:I").Select
    Selection.Copy
    Windows("Triple_Merit_Template.xls").Activate
    Columns("A:A").Select
    ActiveSheet.Paste
    Range("A2").Select

Open in new window

0
Comment
Question by:Seamus2626
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
9 Comments
 
LVL 7

Expert Comment

by:hippohood
ID: 35150191
You can't paste to a sheet, in general. ¿ou should do something like
ActiveCell.Paste

Open in new window

0
 

Author Comment

by:Seamus2626
ID: 35150247
Thanks hippohood, i get the same error though......
0
 
LVL 7

Expert Comment

by:hippohood
ID: 35150255
I am sorry, I am wrong. Yes, you can use the ActiveSheet.Paste.
The problem is somewhere else, let run check your code and see
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:Seamus2626
ID: 35150294
This is my entire sub

Cheers,
Seamus
Sub Fiscal_Merit_Bals()
'
' Fiscal_Merit_Bals Macro
' Macro recorded 09/03/2011 by Kellum
'

'
Dim r As Long

        
    Workbooks.Open Filename:= _
        "G:\Asset Services MI\UnMatched Merit\Triple_Merit_Template.xls"
    Workbooks.Open Filename:="G:\Asset Services MI\UnMatched Merit\Balances.xls"
    
    Windows("Triple_Merit_Template.xls").Activate
    Rows("1:1").Select
    Selection.AutoFilter
    
    
    
    Windows("balances.xls").Activate
    Columns("A:I").Select
    Selection.Copy
    Windows("Triple_Merit_Template.xls").Activate
    Range("A2").Select
    ActiveCell.Paste
    Range("A2").Select
 
    Windows("Balances.xls").Activate
    ActiveWindow.Close
    Range("A2").Select
    
       
End Sub

Open in new window

0
 
LVL 7

Expert Comment

by:hippohood
ID: 35150328
The issue could be one of the followin:
- the mentioned files are not be open when you run the macro
- the mentioned files are open in different INSTANCES of Excel. Try to close both the files, and then open Excel, and open the fioles using File/Open
- there is anothe rprocess, which interrupts macro action
0
 
LVL 7

Expert Comment

by:hippohood
ID: 35150374
In the shown example Line 25 is wrong - you are trying to insert several columns in a cell atrting A2.
You should either define a rectangular area instead of columns (i.e., "A1:I200" instead of "A:I") or incert into cell in the first row (i.e., A1)
0
 
LVL 7

Accepted Solution

by:
hippohood earned 500 total points
ID: 35150481
I could not generate same error with your macro. But it I know it is not unusual to happen, when you are using Copy/Paste with activating Windows. The problem occur because windows don't get activated, turn out to be minimized, editing is in process, active sheet turn out to be a chart, active cell is in a wroing place or a drawing object is active instead of a cell on the target sheet.

Try replacing lines 21-31 with the ones below. Direct references are usually more reliable
Workbooks("balances.xls").Worksheets(1).Range("A1:I250").Copy
    Workbooks("Triple_Merit_Template.xls").Activate
    Workbooks("Triple_Merit_Template.xls").Worksheets(1).Range("A1").Select
    Workbooks("Triple_Merit_Template.xls").Worksheets(1).Paste
    
    Workbooks("Balances.xls").Close

Open in new window

0
 

Author Closing Comment

by:Seamus2626
ID: 35150703
Found it! Some hidden code in Sheet1

Thanks!
0
 
LVL 7

Expert Comment

by:hippohood
ID: 35151773
So, it was an event handler?
Thank you for the points
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question