LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Copy Worksheet to another workbook, programatically?

Given Bob's valuable information:

' assume book1.xls is open, book2.xls may be open or not
' assume not default books, but books with these names,
' previously saved

Sub Tester1()
Dim bOpen
Dim bk1 As Workbook
Dim bk2 As Workbook
Dim sh1 As Worksheet
Dim sh2 As Worksheet
Application.ScreenUpdating = False
Set bk1 = Workbooks("Book1.xls")
Set sh1 = bk1.Worksheets("Sheet1")
On Error Resume Next
Set bk2 = Workbooks("Book2.xls")
bOpen = True
On Error GoTo 0
If bk2 Is Nothing Then
Set bk2 = Workbooks.Open("C:\My Folder\Book2.xls")
End If
sh1.Copy After:=bk2.Worksheets(bk2.Worksheets.Count)
Set sh2 = bk2.Worksheets(bk2.Worksheets.Count)
' or set sh2 = Activesheet
sh2.Name = "ABCD"
If Not bOpen Then
bk2.Close SaveChanges:=True
Else
bk2.Save
End If
Application.ScreenUpdating = True
End Sub

Code untested and may contain typos.
--
Regards,
Tom Ogilvy


Bob Phillips wrote in message
...
You can't copy a worksheet to a closed book, so you will need to open

Book2
first.

--

HTH

Bob Phillips

"plh" wrote in message
...
Hi Everyone,
What I need to do is programatically copy a worksheet from a workbook

(call it
Book1) to another (call it Book2), renaming the Worksheet before it goes

into
Book2. The initial condition being that Book2 is closed. I thought I had

a
way
but I keep running into various problems. I'm not reprinting that here

because I
think I need to start fresh. My question is, what is the cleanest way to

do it?
Thank You all so much in advance,
-plh

I keep hitting "Esc", but I'm still here!





 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy worksheet from one workbook to a master workbook mvannatta Excel Worksheet Functions 3 April 15th 09 08:32 PM
Copy Worksheet from one Workbook to another Workbook Autumn Dreams Excel Discussion (Misc queries) 5 September 12th 08 10:55 PM
How can I programatically change photos in one worksheet Steve Excel Discussion (Misc queries) 10 December 2nd 06 01:07 AM
Copy Data from Workbook into specific Worksheet in other Workbook? kingdt Excel Discussion (Misc queries) 1 March 16th 06 06:55 PM
copy worksheet from closed workbook to active workbook using vba mango Excel Worksheet Functions 6 December 9th 04 07:55 AM


All times are GMT +1. The time now is 10:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"