Method 'Paste' of object '_Worksheet' failed

amer

New Member
Joined
Feb 8, 2005
Messages
1
Hi,

I get the error "Method 'Paste' of object '_Worksheet' failed" when I run the following macro.

Sub SaveVisible()
'
' SaveVisible Macro
' Macro recorded 2/8/2005 by amer
'

'
Cells.Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Workbooks.Add
Cells.Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\amer\My Documents\abcd.txt", _
FileFormat:=xlText, CreateBackup:=False
End Sub

The purpose of the macro is to create a new excel file with the copied data from another file. I don not want to copy hidden rows and columns thus i copy only the visible data.

Could anyone please correct the macro or give a any other method of doing this kind of copy.

Thanks
Amer
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Change:
cells.select
to
[a1].Select

You are trying to paste into a range of a different size than the copy.
 
Upvote 0
Hello Amer, welcome to the board!


Excellent description!! You'd be surprised how many explanations are deficient and/or unrecognizable. Good job!

Maybe you can try something like this ...

Code:
Option Explicit

Sub SaveVisible()
    Dim thisWb As Workbook, thisWs, worksheet
    Dim newWb As Workbook, newWs As worksheet
    Set thisWb = ActiveWorkbook
    Set thisWs = thisWb.ActiveSheet
    Set newWb = Workbooks.Add(xlWBATWorksheet) 'only one sheet
    Set newWs = newWb.Sheets(1)
    thisWs.Cells.SpecialCells(xlCellTypeVisible).Copy newWs.Cells(1, 1)
    ActiveWorkbook.SaveAs Filename:= _
        "C:\Documents and Settings\amer\My Documents\abcd.txt", _
        FileFormat:=xlText, CreateBackup:=False
End Sub

Does this help?
 
Upvote 0

Forum statistics

Threads
1,214,648
Messages
6,120,726
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top