MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old May 24th, 2002, 06:25 AM   #1
poleary2000
Board Regular
 
Join Date: Apr 2002
Location: Pittsburgh, PA
Posts: 317
Default

I am using code to copy a worksheet to a new workbook. The worksheet I am copying has code associated with it. When I copy this worksheet to the new workbook, I want to delete the code from the new worksheet. The originial has to stay the same.

Any ideas?
__________________
Thanks in advance,
Patrick
poleary2000 is offline   Reply With Quote
Old May 24th, 2002, 09:25 AM   #2
poleary2000
Board Regular
 
Join Date: Apr 2002
Location: Pittsburgh, PA
Posts: 317
Default

WOW - No help?

Any suggestions...anyone?
__________________
Thanks in advance,
Patrick
poleary2000 is offline   Reply With Quote
Old May 24th, 2002, 09:39 AM   #3
Ivan F Moala
MrExcel MVP
 
Ivan F Moala's Avatar
 
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
Default

Quote:
On 2002-05-24 08:25, poleary2000 wrote:
WOW - No help?

Any suggestions...anyone?
Patrick...do a search on this.
It has been covered before.
Can't recall....will see if I can drag
out the code before going

__________________
Kind Regards,
Ivan F Moala From the City of Sails
Ivan F Moala is offline   Reply With Quote
Old May 24th, 2002, 09:45 AM   #4
kkknie
Board Regular
 
Join Date: Apr 2002
Location: Greenwood, SC
Posts: 677
Default

I did some searching at Microsoft and in the help files but found nothing. I think the easiest way to do it would be to insert a blank worksheet, copy all of the data from the original (using cells.copy) and paste them on the new one (using cells.paste). Then move the new one to the new workbook.

K
kkknie is offline   Reply With Quote
Old May 24th, 2002, 10:00 AM   #5
Ivan F Moala
MrExcel MVP
 
Ivan F Moala's Avatar
 
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
Default

Try this


Sub RemoveAllCode()
'XL2K:
'Dim VBComp As VBComponent, AllComp As VBComponents, ThisProj As VBProject
'XL97 & XL2K:
Dim VBComp As Object, AllComp As Object, ThisProj As Object
Dim WSht As Worksheet
Dim RemoveOK As Integer, Wbk As Workbook

For Each Wbk In Workbooks
'// Make sure it's not this workbook!!
If Wbk.Name <> ThisWorkbook.Name Then
'// Ask the User Just in case!!
RemoveOK = MsgBox("Remove All code from:= " & Wbk.Name & "?", vbYesNo)
If RemoveOK = vbNo Then GoTo Nxt
Set ThisProj = Wbk.VBProject
Set AllComp = ThisProj.VBComponents

For Each VBComp In AllComp
With VBComp
Select Case .Type
Case 1, 2, 3
'remove modules,Classes & Forms
AllComp.Remove VBComp
Case 100
'Remove Event codes
.CodeModule.DeleteLines 1, .CodeModule.CountOfLines
End Select
End With
Next
End If

Set ThisProj = Nothing
Set AllComp = Nothing

Application.DisplayAlerts = True

Nxt: Next

MsgBox "Done!" & Space(20), vbInformation + vbSystemModal

End Sub


__________________
Kind Regards,
Ivan F Moala From the City of Sails
Ivan F Moala is offline   Reply With Quote
Old May 24th, 2002, 02:03 PM   #6
poleary2000
Board Regular
 
Join Date: Apr 2002
Location: Pittsburgh, PA
Posts: 317
Default

Thanks. The adding of a workbook and using the cells.copy command works fine. However, the format [column sizing, cell merging] is not right. Do I have to paste special or something?

Also, Ivan you answered a question for me the other day regarding e-mail in Excel. You supplied me with this code [I've only included a piece of it]

ActiveWorkbook.SendMail strRecipients, "Your copy of worksheet x"
ActiveWorkbook.Close False

This code sends the e-mail immediately. How can I make it give the user the choice to click send on their own.

Thanks,
Patrick
poleary2000 is offline   Reply With Quote
Old May 24th, 2002, 02:11 PM   #7
poleary2000
Board Regular
 
Join Date: Apr 2002
Location: Pittsburgh, PA
Posts: 317
Default

Also, when copying the cells to the new sheet in the new workbook, how can I retain the old sheets page setup? Can I transfer that to the new one [i.e. landscape, print area, margins,etc.]?

__________________
Thanks in advance,
Patrick
poleary2000 is offline   Reply With Quote
Old Jun 17th, 2002, 09:30 PM   #8
Corni
Board Regular
 
Join Date: Mar 2002
Location: Brampton
Posts: 324
Default

Using Cells.Copy and Cells.Paste, all cells formatting is preserved (i.e. all column widths, font, sizes, cell merging etc. However, the page setup is lost, and has to be done by code.

For giving the user the opportunity to send the email manually, i.e. to click the send button on the Outlook window, add this line of code:

Application.Dialogs(xlDialogSendMail).Show
Corni is offline   Reply With Quote
Old Jun 18th, 2002, 06:15 AM   #9
George J
Board Regular
 
George J's Avatar
 
Join Date: Feb 2002
Location: Edinburgh, Bonnie Scotland
Posts: 820
Default

This is what I use for e-mailing a workbook to clients, without the formulas and code, but retaining the layout and other settings.

Anyone want to alter or amend this, feel free, but let us know how to improve please.

WARNING : the removeCode macro is very effective and should not be run in an original workbook with macros you want to keep.


Sub EMAIL_TellUser()
Dim msg As String
Dim Proceed As Integer

msg = "This routine will create a copy" & vbCr
msg = msg & "of the workbook, but display" & vbCr
msg = msg & "only values, removing all macros." & vbCr
msg = msg & "" & vbCr
msg = msg & "To start this routine click YES" & vbCr
msg = msg & "To cancel this routine Click NO" & vbCr

Proceed = MsgBox(msg, vbInformation + vbYesNo, "Proceed")
If Proceed = vbNo Then End
If Proceed = vbYes Then
Call only_values
Else
End
End If
End Sub


Sub only_values()

Dim wksht As Worksheet


fname = Application.GetSaveAsFilename(filefilter:="Excel Files (*.xls), *.xls")
ActiveWorkbook.SaveCopyAs (fname)
Application.DisplayAlerts = False
Workbooks.Open (fname), False

Application.ScreenUpdating = False

Call removeCode
Call Individual_Fault

numsheets = ActiveWorkbook.Sheets.count

For i = 1 To numsheets
ActiveWorkbook.Sheets(i).Visible = True

Sheets(i).Select

With Sheets(i)
.Cells.Copy
.Cells.PasteSpecial Paste:=xlValues
Application.CutCopyMode = False

Sheets(i).Cells(1, 1).Select

End With

Next i

Application.DisplayAlerts = True
Application.ScreenUpdating = True

ActiveWorkbook.Save

MsgBox "New workbook has been created."

End Sub


Sub removeCode()
Dim awi 'activeWorkbookItem(index)
Dim awcl As Integer 'activeWorkbook Component CountOfLines
Dim count As Integer 'how many potential code modules
Dim i As Integer 'loop counter
On Error Resume Next
count = ActiveWorkbook.VBProject.VBComponents.count
For i = 1 To count
Set awi = ActiveWorkbook.VBProject.VBComponents.Item(i)
awcl = awi.CodeModule.CountOfLines
awi.CodeModule.DeleteLines 1, awcl
Next i
Set awi = Nothing ' Release the object
End Sub


Sub Individual_Fault()
On Error Resume Next
With Application
.CutCopyMode = False
.DisplayAlerts = False
'ActiveWorkbook.Sheets("Individual").Delete 'This sheet kept crashing excel on my system.
.DisplayAlerts = True
End With

End Sub


The macros are NOT all my own, but have taken bits and pieces from other places to enable me to put this thing together.

__________________
George J
George J is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 05:55 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes