473,320 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Kill a Workbook

Hi,

Im having trouble deleting a workbook using VBA. What i want is to open a workbook called "xxxxx waiting", make some modification and then save it as readonly but as a "xxxxx complete". I then want to delete the old workvook "xxxxx waiting"

I though i had it cracked but it doesnt seem to work. Ive put the code below if someone could help.

Thanks in advance

Private Sub Save_Click()

ReqNum = Worksheets("chemicals").Range("D2")

With ActiveWorkbook
.SaveAs Filename:="Z:\Req\" & ReqNum & "Complete", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=True, CreateBackup:=False

End With

Kill "Z:\Req\" & ReqNum & "Waiting"

End Sub
Manny
Aug 1 '07 #1
7 1977
SammyB
807 Expert 512MB
I don't think that you can kill yourself. That would be dangerous. :D You'll need another program to open the workbook, save as, close, and kill.
Aug 1 '07 #2
Killer42
8,435 Expert 8TB
Can you be a bit more specific than "doesn't work"? What does happen?
Aug 2 '07 #3
fplesco
82
Hi,

Im having trouble deleting a workbook using VBA. What i want is to open a workbook called "xxxxx waiting", make some modification and then save it as readonly but as a "xxxxx complete". I then want to delete the old workvook "xxxxx waiting"

I though i had it cracked but it doesnt seem to work. Ive put the code below if someone could help.

Thanks in advance

Private Sub Save_Click()

ReqNum = Worksheets("chemicals").Range("D2")

With ActiveWorkbook
.SaveAs Filename:="Z:\Req\" & ReqNum & "Complete", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=True, CreateBackup:=False

End With

Kill "Z:\Req\" & ReqNum & "Waiting"

End Sub
Manny

Hi there -

You might miss the extension of the file

Try this:
Expand|Select|Wrap|Line Numbers
  1. Kill "Z:\Req\" & ReqNum & "Waiting.xls"
  2.  
Have a nice day!
Aug 2 '07 #4
fplesco
82
Hi,

Im having trouble deleting a workbook using VBA. What i want is to open a workbook called "xxxxx waiting", make some modification and then save it as readonly but as a "xxxxx complete". I then want to delete the old workvook "xxxxx waiting"

I though i had it cracked but it doesnt seem to work. Ive put the code below if someone could help.

Thanks in advance

Private Sub Save_Click()

ReqNum = Worksheets("chemicals").Range("D2")

With ActiveWorkbook
.SaveAs Filename:="Z:\Req\" & ReqNum & "Complete", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=True, CreateBackup:=False

End With

Kill "Z:\Req\" & ReqNum & "Waiting"

End Sub
Manny

Hi there -

You might miss the extension of the file and the space between the ReqNum and Waiting:

Try this:
Expand|Select|Wrap|Line Numbers
  1. Kill "Z:\Req\" & ReqNum & " Waiting.xls"   ' put a single SPACE before Waiting
  2.  
Have a nice day!
Aug 2 '07 #5
Hi there -

You might miss the extension of the file

Try this:
Expand|Select|Wrap|Line Numbers
  1. Kill "Z:\Req\" & ReqNum & "Waiting.xls"
  2.  
Have a nice day!

Thanks worked a treat!!!!
Aug 2 '07 #6
Killer42
8,435 Expert 8TB
... You might miss the extension of the file and the space between the ReqNum and Waiting ...
Thanks again, fplesco.

I'm curious though - are you sure about the space? I've always used Format$() function when printing or concatenating numbers, specifically to prevent the insertion of the extra space. Can never remember though, whether it's before or after the number. (I guess I should go and check.)
Aug 3 '07 #7
Killer42
8,435 Expert 8TB
... I've always used Format$() function when printing or concatenating numbers, specifically to prevent the insertion of the extra space. Can never remember though, whether it's before or after the number. (I guess I should go and check.)
Well, I just set up this elaborate testing scenario...
Expand|Select|Wrap|Line Numbers
  1. ? 5;"h";6;"f";7
which produced the output " 5 h 6 f 7 and confirmed that printing, at least, leaves a space before the number.

But of course (and I'm sure you know where this is heading) a quick test with this code...
Expand|Select|Wrap|Line Numbers
  1. Dim A As String
  2. A = 5 & "h" & 6 & "f" & 7
  3. Debug.Print A
...produced "5h6f7", thus refuting my "extra space" theory. Obviously I've been using Format unnecessarily. Slightly annoying, but I guess it's good that I know better now.
Aug 3 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: A frustrated developer | last post by:
The following article discussed how to use the Excel, close and kill it: http://support.microsoft.com/default.aspx?scid=kb;en-us;317109 But if you added a oBook.SaveAs(...) to save the workbook...
5
by: Josema | last post by:
Hi to all, I have a windows application that uses workbooks, sheets, ranges, etc... This application is consumed by few clients. Some weeks ago I had problems to kill excel.exe process but i...
3
by: hari krishna | last post by:
hi, I am generating excel reports through vb.Net. After creating excel.application and the report is generated, each report leaves Excel in memory. I can see them in task manager in Process tab...
2
by: charmis | last post by:
Hi everyone, I am trying to include one feature using excel object in my application. I am giving the code to create and kill the process , that i got from Microsoft site.......but nothing is...
1
by: Lee Gillie | last post by:
I need to be able to kill a process programmatically under ASP.NET. IIS runs under the local system account. The user accessing the web is using anonymous access. We would prefer NOT to grant...
2
by: touf | last post by:
Hi, I use the folowing code to create a new Excel file using a query It creates an excel file and save it on the disc, but When I double-clic on it (explorer) it open Excel and bloc,(don't display...
2
by: ChrisFrohlich | last post by:
I have been trying to use the Office PIA's to write an ASP.NEt page to: 1. Open a template workbook 2. Populate some data 3. Save the file back to the server 4. Quit Excel and free up Memory I...
0
by: bettatronic | last post by:
The goal : to have class which is able to add some OLE objects on the sheet runtime. Instances of the class must be accessible from any public/private module. Okay, I've experimented for so long &...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.