I have done a fair amount of searching about this and have yet to find a working solution...
Goal – to programmatically copy spreadsheets (in Excel 2007) from one workbook and paste them into a new one. These sheets contain hidden rows which should not be in the new one.
Problem - The hidden rows are showing in the new one.
I am working with existing code - originally in Excel 2003.
'Copy from the current workbook -
Sheets(n).Select
Cells.Select
Selection.Copy
'Go to new workbook
Windows(NewWorkbook).Activate
Cells.Select
'Paste into new workbook
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
___________________________________________
Attempted fix 1
‘Try visible cells only (copy)
Sheets(n).Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Windows(NewWorkbook).Activate
Cells.Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
The "Selection.Copy" line produces this error:
"Run-time error '1004':
This command cannot be used on multiple selections."
__________________________________________________
Attempted fix 2
'Try paste of picture – (paste into new)
Sheets(n).Select
Cells.Select
Selection.Copy
Windows(NewWorkbook).Activate
Cells.Select
Selection.PasteSpecial Format:="Picture (Enhanced Metafile)", Link:=False, DisplayAsIcon:=False
The "Selection.PasteSpecial ..." line produces this error:
"Run-time error '1004':
Application-defined or Object-defined error"
Note: I tried several versions of the above one including copying it as a picture.
___________________________________________
I am fairly new to VBA coding so any help would be greatly appreciated.
Bill
Bookmarks