Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Programiclly copying worksheet to another workbook

I would like to create a function that will get a filename from a cell,
then copy worksheets from a different workbook,to a differnt workbook with
a new name.

for example: In Book1 I have 1 sheet. Labeled "SheetstoCopy"
It will have a list of of the sheets I want to copy for workbook2
WS1, WS2,WS3 would be in column A and col B would have OrigFileName1 Col C
would have Workbook2

I would like to call the function, hopefully like WSCopy("WS1",
"OrigFileName1", "WorkBook2")
and what would happen is it would insert a new sheet into WorkBook2, naming
it "OrigFileName1-WS1" (or pass a new name as a parameter)

Then it would select all (including hidden) OrigFileName1.WS1, and then copy
it to Workbook2.OrigFileName1-WS1


HEre is what I have figured out with hard coded names., but I get a
subscript out of range error
I would LIKE to have it so I can pass varibles to it.

Thanks
Phil



Sub CopyWS()
wsName = "Master"
WB1 = "11-27-03.xls"
WB2 = "Testq.xls"
Dim currentws As String
'currentws = ActiveWorksheet.Name
MsgBox wsName
MsgBox WB1
MsgBox WB2
newName = WB2 & "." & wsName
Workbooks(WB1).Worksheets(wsName).Activate

ActiveWorksheet.Copy After:=Worksheets(newName) ' this gives me a subsript
out of range...
'currentws.Activate

End Sub




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Programiclly copying worksheet to another workbook


variable NewName is set to workbook name & work sheet name
newName = WB2 & "." & wsName

you then try and insert copied sheet after a sheet with this combine
name which does not exist

try

Workbooks(WB1).Worksheets(wsName)..Cop
After:=workbooks(wb2).Worksheets(1

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com

Reply
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
Copying a worksheet to another workbook Dutch Excel Discussion (Misc queries) 6 August 10th 07 05:01 PM
Copying a worksheet into the same workbook Michael New Users to Excel 9 February 6th 06 08:35 PM
Copying A Worksheet From Each Open Workbook to an new Workbook carl Excel Worksheet Functions 1 January 3rd 06 05:37 PM
Copying worksheet from workbook to another Mark Jackson Excel Worksheet Functions 0 January 14th 05 09:05 PM
Copying worksheet to another workbook Haider Quazilbash Excel Programming 2 September 22nd 03 06:23 PM


All times are GMT +1. The time now is 01:36 AM.

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

About Us

"It's about Microsoft Excel"