#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Delete WB

I have two WorkBooks (in the same directory) open Test and TestX. From Test
I want to close and delete TestX. The code I am ussing is;

Sub Delete WB()
sName = ThisWorkbook.FullName
sName = Left(sName, Len(sName) - 4) & "X.xls"
Workbooks("sName").Close SaveChanges:=False
Kill "sName"
End Sub

It errors on the close statement. What am I doing wrong?

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Delete WB

I think you want

Sub Delete WB()
sName = ThisWorkbook.FullName
sName = Left(sName, Len(sName) - 4) & "X.xls"
Workbooks(sName).Close SaveChanges:=False
Kill "sName"
End Sub


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Ronbo" wrote in message
...
I have two WorkBooks (in the same directory) open Test and TestX. From

Test
I want to close and delete TestX. The code I am ussing is;

Sub Delete WB()
sName = ThisWorkbook.FullName
sName = Left(sName, Len(sName) - 4) & "X.xls"
Workbooks("sName").Close SaveChanges:=False
Kill "sName"
End Sub

It errors on the close statement. What am I doing wrong?

Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Delete WB

..fullname includes the drive and path.

Workbooks(sName) <-- no quotes around the variable
wants just the name (no drive, no path)

sname = thisworkbook.name
sName = Left(sName, Len(sName) - 4) & "X.xls"
workbooks(sName).close savechanges:=false
kill thisworkbook.path & "\" & sname

(You'd still want to specify the full path for the kill statement.)

Ronbo wrote:

I have two WorkBooks (in the same directory) open Test and TestX. From Test
I want to close and delete TestX. The code I am ussing is;

Sub Delete WB()
sName = ThisWorkbook.FullName
sName = Left(sName, Len(sName) - 4) & "X.xls"
Workbooks("sName").Close SaveChanges:=False
Kill "sName"
End Sub

It errors on the close statement. What am I doing wrong?

Thanks


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Delete WB

Hi there,

I am not sure why your code is not working.

but here is one that does

Sub Delete_WB()
sName = ThisWorkbook.Name
sName = Left(sName, Len(sName) - 4) & "X.xls"
Windows(sName).Activate
ActiveWindow.Close

fName = ThisWorkbook.FullName
pName = Left(fName, Len(fName) - 4) & "X.xls"

Kill pName
End Sub



"Ronbo" wrote in message
...
I have two WorkBooks (in the same directory) open Test and TestX. From
Test
I want to close and delete TestX. The code I am ussing is;

Sub Delete WB()
sName = ThisWorkbook.FullName
sName = Left(sName, Len(sName) - 4) & "X.xls"
Workbooks("sName").Close SaveChanges:=False
Kill "sName"
End Sub

It errors on the close statement. What am I doing wrong?

Thanks



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Delete WB

Thnaks to both of you. Your time and help is truly appreciated.

"Dave Peterson" wrote:

..fullname includes the drive and path.

Workbooks(sName) <-- no quotes around the variable
wants just the name (no drive, no path)

sname = thisworkbook.name
sName = Left(sName, Len(sName) - 4) & "X.xls"
workbooks(sName).close savechanges:=false
kill thisworkbook.path & "\" & sname

(You'd still want to specify the full path for the kill statement.)

Ronbo wrote:

I have two WorkBooks (in the same directory) open Test and TestX. From Test
I want to close and delete TestX. The code I am ussing is;

Sub Delete WB()
sName = ThisWorkbook.FullName
sName = Left(sName, Len(sName) - 4) & "X.xls"
Workbooks("sName").Close SaveChanges:=False
Kill "sName"
End Sub

It errors on the close statement. What am I doing wrong?

Thanks


--

Dave Peterson

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
Macro to delete sheets and saves remaining file does not properly delete module pherrero Excel Programming 1 June 22nd 05 01:12 AM
Macro to delete sheets and saves remaining file does not properly delete module bhawane Excel Programming 0 June 21st 05 04:53 PM
Macro to delete sheets and saves remaining file does not properly delete module pherrero Excel Programming 0 June 21st 05 04:38 PM
Macro to delete sheets and saves remaining file does not properly delete module bhawane Excel Programming 0 June 21st 05 04:20 PM
Delete every 3rd row, then delete rows 2-7, move info f/every 2nd row up one to the end and delete the row below Annette[_4_] Excel Programming 2 September 21st 04 02:40 PM


All times are GMT +1. The time now is 06:44 AM.

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"