#1   Report Post  
Johan
 
Posts: n/a
Default copy workbook

Hi,

I want to do the following with a macro:

Msgbox: "copy?" if Yes
Then
Active wbk - sheet1 - range("name1") and active wbk - sheet2 -
range("name2") copy to new wbk without formulas and macro.
Then
Save as: range("name").xls

Please, can anyone help me!

Thanks in advance,

Johan
  #2   Report Post  
Nick Hodge
 
Posts: n/a
Default

Johan

Not quite sure what you want the new workbook saved as but this should help

Sub CopySheets()
Dim wbNew As Workbook
Dim iAnswer As Integer
iAnswer = MsgBox("Copy Worksheets?", vbYesNo + vbQuestion, "Copy
Workbooks?")
If iAnswer = vbNo Then Exit Sub
Range("Name1").Value = Range("Name1").Value
Range("Name2").Value = Range("Name2").Value
Worksheets("Sheet1").Copy
Set wbNew = ActiveWorkbook
ThisWorkbook.Worksheets("Sheet2").Copy After:=wbNew.Worksheets(1)
wbNew.SaveAs Filename:=ThisWorkbook.Path & "\RangeName.xls"
ThisWorkbook.Close SaveChanges:=False
End Sub

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
HIS


"Johan" wrote in message
om...
Hi,

I want to do the following with a macro:

Msgbox: "copy?" if Yes
Then
Active wbk - sheet1 - range("name1") and active wbk - sheet2 -
range("name2") copy to new wbk without formulas and macro.
Then
Save as: range("name").xls

Please, can anyone help me!

Thanks in advance,

Johan



  #3   Report Post  
Johan
 
Posts: n/a
Default

Hi Nick,

This works fine, but it copies the formulas and macros. Is there a way
to copy only data and layout?

Thanks in avance.

Johan


"Nick Hodge" wrote in message ...
Johan

Not quite sure what you want the new workbook saved as but this should help

Sub CopySheets()
Dim wbNew As Workbook
Dim iAnswer As Integer
iAnswer = MsgBox("Copy Worksheets?", vbYesNo + vbQuestion, "Copy
Workbooks?")
If iAnswer = vbNo Then Exit Sub
Range("Name1").Value = Range("Name1").Value
Range("Name2").Value = Range("Name2").Value
Worksheets("Sheet1").Copy
Set wbNew = ActiveWorkbook
ThisWorkbook.Worksheets("Sheet2").Copy After:=wbNew.Worksheets(1)
wbNew.SaveAs Filename:=ThisWorkbook.Path & "\RangeName.xls"
ThisWorkbook.Close SaveChanges:=False
End Sub

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
HIS


"Johan" wrote in message
om...
Hi,

I want to do the following with a macro:

Msgbox: "copy?" if Yes
Then
Active wbk - sheet1 - range("name1") and active wbk - sheet2 -
range("name2") copy to new wbk without formulas and macro.
Then
Save as: range("name").xls

Please, can anyone help me!

Thanks in advance,

Johan

  #4   Report Post  
Nick Hodge
 
Posts: n/a
Default

Johan

Do the sheets have code behind them?

If not the newly created workbook 'RangeName.xls' will have no formulae or
code in it.

The two lines of Range("Name1") and 2 'kill' the formulas by setting them to
the value of themselves and moving the sheets to a workbook without code
ensures there is none, so the only remaining possibility is code behind the
sheets?

Maybe I am misunderstanding?

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
HIS


"Johan" wrote in message
om...
Hi Nick,

This works fine, but it copies the formulas and macros. Is there a way
to copy only data and layout?

Thanks in avance.

Johan


"Nick Hodge" wrote in message
...
Johan

Not quite sure what you want the new workbook saved as but this should
help

Sub CopySheets()
Dim wbNew As Workbook
Dim iAnswer As Integer
iAnswer = MsgBox("Copy Worksheets?", vbYesNo + vbQuestion, "Copy
Workbooks?")
If iAnswer = vbNo Then Exit Sub
Range("Name1").Value = Range("Name1").Value
Range("Name2").Value = Range("Name2").Value
Worksheets("Sheet1").Copy
Set wbNew = ActiveWorkbook
ThisWorkbook.Worksheets("Sheet2").Copy After:=wbNew.Worksheets(1)
wbNew.SaveAs Filename:=ThisWorkbook.Path & "\RangeName.xls"
ThisWorkbook.Close SaveChanges:=False
End Sub

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
HIS


"Johan" wrote in message
om...
Hi,

I want to do the following with a macro:

Msgbox: "copy?" if Yes
Then
Active wbk - sheet1 - range("name1") and active wbk - sheet2 -
range("name2") copy to new wbk without formulas and macro.
Then
Save as: range("name").xls

Please, can anyone help me!

Thanks in advance,

Johan



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
copy COLUMN from 1 worksheet to another (in a different workbook) DavidB Excel Discussion (Misc queries) 3 January 15th 05 02:47 PM
copy a workbook from other workbook with lot of sheets wit... Vai Excel Discussion (Misc queries) 1 January 3rd 05 10:27 PM
How can I save an editable copy of a protected excel workbook? randyice Excel Discussion (Misc queries) 1 December 23rd 04 09:01 PM
copy range of cells from one workbook to another mitmeez Excel Discussion (Misc queries) 1 December 9th 04 08:14 PM
how can I duplicate or copy a workbook then divide selected cells. macros excel... duplication and calculat Excel Discussion (Misc queries) 1 November 29th 04 03:16 PM


All times are GMT +1. The time now is 12:08 PM.

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"