Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro - worksheets to new workbook


Hi all,

I'm trying to come up with a macro that will add a new workbook and
copy certain sheets from the old workbook to the new one. However, I
also need to be able to prompt the user to name the new workbook. and
then have the macro know that the sheets from the old workbook go into
the newly named one.
I was able to come up with a macro that would do this but everytime i
ran the macro it would automatically call the added workbook "book1"
then "book2" and so on but the macro code still referred to it as "book
1" and would subsequently error out.

Can anybody offer any advice?

Thank you very much...


--
natijoe
------------------------------------------------------------------------
natijoe's Profile: http://www.excelforum.com/member.php...o&userid=25556
View this thread: http://www.excelforum.com/showthread...hreadid=393074

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Macro - worksheets to new workbook

Here is a little code to help you. Without seeing your code it is hard to be
too specific...

Sub CopyToNewBook()
Dim wbk As Workbook

Set wbk = Workbooks.Add

Sheet1.Copy wbk.Sheets(wbk.Sheets.Count)
wbk.Activate
Application.Dialogs(xlDialogSaveAs).Show "C:\MyBook.xls"

End Sub
--
HTH...

Jim Thomlinson


"natijoe" wrote:


Hi all,

I'm trying to come up with a macro that will add a new workbook and
copy certain sheets from the old workbook to the new one. However, I
also need to be able to prompt the user to name the new workbook. and
then have the macro know that the sheets from the old workbook go into
the newly named one.
I was able to come up with a macro that would do this but everytime i
ran the macro it would automatically call the added workbook "book1"
then "book2" and so on but the macro code still referred to it as "book
1" and would subsequently error out.

Can anybody offer any advice?

Thank you very much...


--
natijoe
------------------------------------------------------------------------
natijoe's Profile: http://www.excelforum.com/member.php...o&userid=25556
View this thread: http://www.excelforum.com/showthread...hreadid=393074


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Macro - worksheets to new workbook

This is a small variation that allows the user to select the filename of the
new workbook.

Sub Test()
Dim NewWkb As Workbook
Dim OldWkb As Workbook
Dim sFileName As String
Dim fd As FileDialog

Set OldWkb = ActiveWorkbook

Set fd = Application.FileDialog(msoFileDialogSaveAs)

If fd.Show = -1 Then
sFileName = fd.SelectedItems(1)

Set NewWkb = Workbooks.Add()

NewWkb.SaveAs sFileName

OldWkb.Activate

OldWkb.Worksheets("One").Copy , NewWkb.Sheets("Sheet3")
'Will Copy after Sheet3 in New Workbook
'Copy additional sheets using same command as above
End If

Set NewWkb = Nothing
Set OldWkb = Nothing
Set fd = Nothing

End Sub

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


"natijoe" wrote in
message ...

Hi all,

I'm trying to come up with a macro that will add a new workbook and
copy certain sheets from the old workbook to the new one. However, I
also need to be able to prompt the user to name the new workbook. and
then have the macro know that the sheets from the old workbook go into
the newly named one.
I was able to come up with a macro that would do this but everytime i
ran the macro it would automatically call the added workbook "book1"
then "book2" and so on but the macro code still referred to it as "book
1" and would subsequently error out.

Can anybody offer any advice?

Thank you very much...


--
natijoe
------------------------------------------------------------------------
natijoe's Profile:
http://www.excelforum.com/member.php...o&userid=25556
View this thread: http://www.excelforum.com/showthread...hreadid=393074


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro - worksheets to new workbook


Thanks Jim. That helped a lot.
And David, I was just going to ask the same question that you already
answered... Thank you very much.

Could you explain what the "fd as File Dialogue" does?

Thank you.


--
natijoe
------------------------------------------------------------------------
natijoe's Profile: http://www.excelforum.com/member.php...o&userid=25556
View this thread: http://www.excelforum.com/showthread...hreadid=393074

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Macro - worksheets to new workbook

The FileDialog object allows you to access the same dialog boxes that Excel
gives you when you choose "Save As" or "Open" from the File Menu for
instance. The user can browse to a particular directory and choose a
filename. The new workbook is then saved to this directory and filename.

You can find more information on the FileDialog object he

http://support.microsoft.com/default...b;en-us;288543

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


"natijoe" wrote in
message ...

Thanks Jim. That helped a lot.
And David, I was just going to ask the same question that you already
answered... Thank you very much.

Could you explain what the "fd as File Dialogue" does?

Thank you.


--
natijoe
------------------------------------------------------------------------
natijoe's Profile:
http://www.excelforum.com/member.php...o&userid=25556
View this thread: http://www.excelforum.com/showthread...hreadid=393074


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
Combine worksheets in multiple workbook in one workbook with a macro Sam Commar Excel Discussion (Misc queries) 2 April 2nd 09 01:09 PM
Apply Macro to all worksheets in a workbook except one Carrie_Loos via OfficeKB.com Excel Discussion (Misc queries) 5 January 15th 09 10:03 PM
Macro to paste worksheets in another workbook [email protected] Excel Discussion (Misc queries) 0 March 28th 07 02:13 PM
Applying same macro to all worksheets in workbook [email protected] Excel Discussion (Misc queries) 2 October 19th 05 11:25 PM
Run macro on all worksheets within workbook Marek Socha Excel Programming 4 December 15th 03 06:36 PM


All times are GMT +1. The time now is 09:50 AM.

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"