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

Hello All

I have a workbook A with around 20 worksheets in it. I wish to copy 3
specific worksheets to a new workbook B.

I have a written the following VBA code to perform the operation:

Private Sub cmdSaveData_Click()
Dim FN As String 'get user to select a file
FN = Application.GetSaveAsFilename(fileFilter:="Excel Files (*.xls),
*.xls")
If FN = "False" Then
MsgBox "File Save Cancelled by User"
Else
Sheets("DataX").Select
Sheets("DataX").Copy
ActiveWorkbook.SaveAs Filename:=FN, _
FileFormat:=xlNormal, Password:="", _
WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
ActiveWorkbook.Close SaveChanges:=False
End If
End Sub

Problem: The worksheet being copied has VBA codes associated with it which
I do not want copied to the new workbook. How can I copy just the sheet
without the VBA code & links; i.e. copy only the VALUES and FORMATTING

Any help is greatly appreciated.

Haider


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

Haider,

Start with this and adapt it to your code...
[watch for word wrap]

Sheets("DataX").Cells.Copy
Workbooks.Add
Cells(1, 1).PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
Cells(1, 1).PasteSpecial Paste:=xlFormats, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False

You might want to use Workbooks().Sheets().Range() references to more
easily go between the 2 books.

--
sb
"Haider Quazilbash" wrote in message
...
Hello All

I have a workbook A with around 20 worksheets in it. I wish to copy 3
specific worksheets to a new workbook B.

I have a written the following VBA code to perform the operation:

Private Sub cmdSaveData_Click()
Dim FN As String 'get user to select a file
FN = Application.GetSaveAsFilename(fileFilter:="Excel Files (*.xls),
*.xls")
If FN = "False" Then
MsgBox "File Save Cancelled by User"
Else
Sheets("DataX").Select
Sheets("DataX").Copy
ActiveWorkbook.SaveAs Filename:=FN, _
FileFormat:=xlNormal, Password:="", _
WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
ActiveWorkbook.Close SaveChanges:=False
End If
End Sub

Problem: The worksheet being copied has VBA codes associated with it

which
I do not want copied to the new workbook. How can I copy just the sheet
without the VBA code & links; i.e. copy only the VALUES and FORMATTING

Any help is greatly appreciated.

Haider




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Copying worksheet to another workbook

Private Sub cmdSaveData_Click()
Dim FN As String 'get user to select a file
FN = Application.GetSaveAsFilename(fileFilter:="Excel Files (*.xls),
*.xls")
If FN = "False" Then
MsgBox "File Save Cancelled by User"
Else
' Sheets("DataX").Select
Sheets("DataX").Copy
ActiveSheet.UsedRange.Formula = Activesheet.UsedRange.Value
ActiveWorkbook.SaveAs Filename:=FN, _
FileFormat:=xlNormal, Password:="", _
WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
ActiveWorkbook.Close SaveChanges:=False
End If
End Sub

To get rid of the code, you would need to look a Chip Pearson's site

http://www.cpearson.com/excel/vbe.htm

for the basics.

--
Regards,
Tom Ogilvy



"Haider Quazilbash" wrote in message
...
Hello All

I have a workbook A with around 20 worksheets in it. I wish to copy 3
specific worksheets to a new workbook B.

I have a written the following VBA code to perform the operation:

Private Sub cmdSaveData_Click()
Dim FN As String 'get user to select a file
FN = Application.GetSaveAsFilename(fileFilter:="Excel Files (*.xls),
*.xls")
If FN = "False" Then
MsgBox "File Save Cancelled by User"
Else
Sheets("DataX").Select
Sheets("DataX").Copy
ActiveWorkbook.SaveAs Filename:=FN, _
FileFormat:=xlNormal, Password:="", _
WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
ActiveWorkbook.Close SaveChanges:=False
End If
End Sub

Problem: The worksheet being copied has VBA codes associated with it

which
I do not want copied to the new workbook. How can I copy just the sheet
without the VBA code & links; i.e. copy only the VALUES and FORMATTING

Any help is greatly appreciated.

Haider




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 worksheet to another workbook Dig Excel Worksheet Functions 3 October 30th 08 09:01 PM
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


All times are GMT +1. The time now is 11:06 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"