Solved

Application defined error

Posted on 2011-03-16
9
206 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

626 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