Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Application defined error

Posted on 2011-03-16
9
Medium Priority
?
207 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes a serious pitfall that can happen when deleting shapes using VBA.
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 …
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

670 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