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 Apr 22nd, 2002, 05:55 PM   #1
Saa62
New Member
 
Join Date: Mar 2002
Posts: 20
Default

I know this may sound strange, but I want to be able to delete the file after the macro has been run. Part of the macro makes a copy of the file into another folder. The original file needs to be deleted after the file has been copied. Is this possible?

Thanks

Scott
Saa62 is offline   Reply With Quote
Old Apr 22nd, 2002, 07:20 PM   #2
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

Hi
I'm not sure how you would do that...
You cannot delete an open file.
Therefor, a file cannot delete it's self.
You might want to activate the copy, and then run a macro which would close the original workbook and delete it...
Of course these instructions would need to be placed in a contitional If...Then statement...
Am curious about this one...
Will try and see if it can be done with what I know???
Tom
Tom Schreiner is offline   Reply With Quote
Old Apr 22nd, 2002, 07:33 PM   #3
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

Hi
I figured out a way to do it...
But I am going to need to post a topic as well..
The macro which saves the copy of the activeworkbook to another folder can create a text file which can be imported via the open statement of the copy it's self.
I'm pretty sure you can import text into a VBA project via code. Will find out.
Tom
Tom Schreiner is offline   Reply With Quote
Old Apr 22nd, 2002, 07:35 PM   #4
Jay Petrulis
MrExcel MVP
 
Jay Petrulis's Avatar
 
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
Default

Hi,

It is possible.

Check the following thread:

http://groups.google.com/groups?hl=e...nnrp1.deja.com

In a later post, Chip Pearson posted the routine to do it (original credit to Jim Rech).

'----------------
Sub Suicide()
Dim FName As String
Dim Ndx As Integer
With ThisWorkbook
.Save
For Ndx = 1 To Application.RecentFiles.Count
If Application.RecentFiles(Ndx).Path = .FullName Then
Application.RecentFiles(Ndx).Delete
Exit For
End If
Next Ndx
.ChangeFileAccess Mode:=xlReadOnly
Kill .FullName
.Close SaveChanges:=False
End With
End Sub
'------------------

Bye,
Jay
Jay Petrulis is offline   Reply With Quote
Old Apr 22nd, 2002, 07:47 PM   #5
Mark O'Brien
MrExcel MVP
 
Mark O'Brien's Avatar
 
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
Default

Nice one, Jay. I was setting up to have a crack at this one, then read TsTom's reply to his own post. (related to this post)

EDIT:: I also read the whole thread. Nice to see MS Excel MVP's getting slapping each other around.
_________________
[b] Mark O'Brien

[ This Message was edited by: Mark O'Brien on 2002-04-22 18:51 ]
Mark O'Brien is offline   Reply With Quote
Old Apr 22nd, 2002, 08:44 PM   #6
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

Thanks for the reply Jay...
Will put that block in Tom's "neat stuff" workbook.
Thanks,
Tom
Tom Schreiner is offline   Reply With Quote
Old Apr 23rd, 2002, 03:18 AM   #7
Colo
MrExcel MVP
 
Colo's Avatar
 
Join Date: Mar 2002
Location: Kobe, Japan
Posts: 1,420
Default

Hi all. I also thought by another method.

Sub Suicide2()
Dim NB As Object
Set NB = Workbooks.Add
With Application
.DisplayAlerts = False
With ThisWorkbook
Open .Path & "xx.bas" For Output As #1
Print #1, "Sub Temp"
Print #1, "Workbooks(" & """" & .Name & """" & ").Close False"
Print #1, "Kill " & """" & .Path & "" & .Name & """"
Print #1, "Kill " & """" & .Path & "xx.bas" & """"
Print #1, "ThisWorkbook.Close False"
Print #1, "End Sub"
Close #1
NB.VBProject.VBComponents.Import FileName:=.Path & "xx.bas"
End With
.OnTime Now(), NB.Name & "!Temp"
.DisplayAlerts = True
End With
End Sub

Regards,
Colo
Colo is offline   Reply With Quote
Old Apr 23rd, 2002, 03:55 AM   #8
Saa62
New Member
 
Join Date: Mar 2002
Posts: 20
Default

This site is amazing. It has saved me days worth of work. Many thanks to all who have helped. Everyone I work with thinks I am a genious to get excel to do all these neat tricks. I do give credit to all of you that helped. Due to newly received prioities for me, it may be awhile before I will be able to get this information implemented, but I am sure it will work, everthing else that I have gotten from this site has worked great.

Thanks again

Scott
Saa62 is offline   Reply With Quote
Old Apr 29th, 2002, 07:37 PM   #9
Jay Petrulis
MrExcel MVP
 
Jay Petrulis's Avatar
 
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
Default

Quote:
On 2002-04-23 02:55, Saa62 wrote:
This site is amazing. It has saved me days worth of work. Many thanks to all who have helped. Everyone I work with thinks I am a genious to get excel to do all these neat tricks. I do give credit to all of you that helped. Due to newly received prioities for me, it may be awhile before I will be able to get this information implemented, but I am sure it will work, everthing else that I have gotten from this site has worked great.

Thanks again

Scott
Sorry to bring this up to the top of the board (I was searching for this routine and saw the follow up posts)

Scott has broken a cardinal rule with his colleagues at work...

Never, never, never give the credit to anyone else, that is what blame is for!!! Take *ALL* the glory yourself.

Of course, recommend the site later, but you are a genius at work because of *your* efforts. Deny all when you are asked if you received any help.



Bye,
Jay

[ This Message was edited by: Jay Petrulis on 2002-04-29 18:39 ]
Jay Petrulis is offline   Reply With Quote
Old Apr 29th, 2002, 07:43 PM   #10
Anne Troy
MrExcel MVP
 
Anne Troy's Avatar
 
Join Date: Feb 2002
Location: Allentown, PA
Posts: 2,510
Default

I agree with Jay.

The thing is...

It's soooo unbelievable how many people DON'T KNOW ABOUT ALL THE FREE TECH SUPPORT SITES!

Or it's against their religion or something to use them. (Actually, I think it's their egos getting in the way---asking for help is very hard for some people to do.)
__________________
~Anne Troy
Anne Troy 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 11:35 AM.


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