PC Review


Reply
Thread Tools Rate Thread

Copy sheet from file to file

 
 
Otto Moehrbach
Guest
Posts: n/a
 
      22nd Oct 2007
Excel XP & Win XP
wbFile2 and wbFDB are variables and are set to 2 open workbooks. Both have
a sheet called "Names".
I want to delete the "Names" sheet in wbFDB and copy the "Names" sheet from
wbFile2 to wbFDB.
The sheet does get deleted in wbFDB. Good!
But the last line, to copy the sheet, does not work.
Sub CopyNamesSht()
'wbFile2 is the active workbook
Application.DisplayAlerts = False
wbFDB.Sheets("Names").Delete
Application.DisplayAlerts = True
Sheets("Names").Copy After:=wbFDB.Sheets("COJDatabase")
End Sub
What am I doing wrong in the last line? Thanks for your time. Otto


 
Reply With Quote
 
 
 
 
Chip Pearson
Guest
Posts: n/a
 
      23rd Oct 2007
Your code worked fine for me. What problems are you having? I would suggest
that you prefix any reference to a worksheet with the workbook reference. It
makes things easier since you don't have to worry about what workbook
happens to be active at the time.

Sheets("Names").Copy After:=wbFDB.Sheets("COJDatabase")
is better to write as
wbFile2.Sheets("Names").Copy After:=wbFDB.Sheets("COJDatabase")


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)

"Otto Moehrbach" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Excel XP & Win XP
> wbFile2 and wbFDB are variables and are set to 2 open workbooks. Both
> have a sheet called "Names".
> I want to delete the "Names" sheet in wbFDB and copy the "Names" sheet
> from wbFile2 to wbFDB.
> The sheet does get deleted in wbFDB. Good!
> But the last line, to copy the sheet, does not work.
> Sub CopyNamesSht()
> 'wbFile2 is the active workbook
> Application.DisplayAlerts = False
> wbFDB.Sheets("Names").Delete
> Application.DisplayAlerts = True
> Sheets("Names").Copy After:=wbFDB.Sheets("COJDatabase")
> End Sub
> What am I doing wrong in the last line? Thanks for your time. Otto
>


 
Reply With Quote
 
Otto Moehrbach
Guest
Posts: n/a
 
      23rd Oct 2007
Chip
Thanks for that. I don't know if this is a problem but both files have
the exact same code except for the particular code that is the subject of
this thread. And there is a lot of code in these files. Could that upset
Excel?
I could delete ALL the code from the wbFile2 workbook if that would
help, but I would have to do that via VBA. Thanks again. Otto
"Chip Pearson" <(E-Mail Removed)> wrote in message
news:EDE401AE-F97F-4304-95BC-(E-Mail Removed)...
> Your code worked fine for me. What problems are you having? I would
> suggest that you prefix any reference to a worksheet with the workbook
> reference. It makes things easier since you don't have to worry about what
> workbook happens to be active at the time.
>
> Sheets("Names").Copy After:=wbFDB.Sheets("COJDatabase")
> is better to write as
> wbFile2.Sheets("Names").Copy After:=wbFDB.Sheets("COJDatabase")
>
>
> --
> Cordially,
> Chip Pearson
> Microsoft MVP - Excel, 10 Years
> Pearson Software Consulting
> www.cpearson.com
> (email on the web site)
>
> "Otto Moehrbach" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Excel XP & Win XP
>> wbFile2 and wbFDB are variables and are set to 2 open workbooks. Both
>> have a sheet called "Names".
>> I want to delete the "Names" sheet in wbFDB and copy the "Names" sheet
>> from wbFile2 to wbFDB.
>> The sheet does get deleted in wbFDB. Good!
>> But the last line, to copy the sheet, does not work.
>> Sub CopyNamesSht()
>> 'wbFile2 is the active workbook
>> Application.DisplayAlerts = False
>> wbFDB.Sheets("Names").Delete
>> Application.DisplayAlerts = True
>> Sheets("Names").Copy After:=wbFDB.Sheets("COJDatabase")
>> End Sub
>> What am I doing wrong in the last line? Thanks for your time. Otto
>>

>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy Sheet to New File Without Code Todd Microsoft Excel Programming 5 7th Oct 2009 05:46 PM
copy the same raws of all sheets from about a 100 file to a new sheet of a book and save the file attis555@hotmail.com Microsoft Excel Setup 0 14th Mar 2007 02:13 AM
Copy sheet to a new file Pete Microsoft Excel Misc 3 5th Feb 2005 10:37 PM
Copy To Sheet In Another File. kumawat_s Microsoft Excel Discussion 2 18th Oct 2004 05:06 PM
Copy sheet to another specified file Rob Microsoft Excel Programming 1 22nd May 2004 07:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:52 PM.