Copy generates an automation error.

R

Richard

Hi, everybody

The following code works just one time. If It runs again without
exiting Excel it generates an automation error. Why ? Any workaround ?
Is there a problem with tyhe Copy method ?

Public Sub Atry()
'***
Dim aw As Workbook
Set aw = ActiveWorkbook
Workbooks.Open "c:\temp.xls"
ActiveSheet.Copy After:=aw.Sheets(aw.Sheets.Count) '<-- This were the
problem is
Windows("temp.xls").Close
Set aw = Nothing
End Sub
 
T

Tom Ogilvy

The code ran several times for me with no problem, so there is nothing wrong
with the code. If there is a problem, it must be related to you
workbooks/environment. Perhaps you have hidden sheets or something in the
destination workbook which are causing the problem - it would be hard to
tell.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top