Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copying a sheet into another workbook 1

Status
Not open for further replies.

logius

Programmer
Aug 30, 2001
175
US
Hey there. I'm working on a set of macros that will be stored in a PERSONAL.XLS file. What I'm trying to do at the moment is copy the entire contents of an open Sheet (the name of the sheet will always be the same, but the data inside is variable) into the PERSONAL.XLS file only using VBA code. I tried the following code, but got an error ("Error 1004: application-defined or user-defined error").

Code:
Sheets("output_file").Copy _ 'the name of the sheet to be copied
        Destination:=Workbooks("personal.xls").Sheets("Sheet1").Range("A1")

Now one of the problems I've been having is that I can't add modules to the first sheet/workbook (circumstances don't allow for it) and that's been limiting me for some time now. I would appreciate any help anyone could give.
 
I think the cause of error is that the personal workbook is invisible. Try for one:

Dim VHide As Boolean, ActSh As Object
Set ActSh = ActiveSheet
If Not Workbooks("Personal").Windows(1).Visible Then
VHide = False
else
VHide = True
end if
Workbooks("Personal").Windows(1).Visible = True
ActSh.Copy After:=Workbooks("Personal").Sheets(1)
Workbooks("Personal").Windows(1).Visible = VHide
 
Yeah, that worked great, Ide. Thanks alot, referencing other workbooks/worksheets/etc. is something I'm just getting the hang of.

thanks,
Log
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top