Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Delete new sheets?

I have this macro which copies all of the 1st sheets from any excel
files in my c:\ directory.

Option Explicit
Private root As String
Sub ListFiles()
Dim sFileName As String
Dim index As Long
Dim ws As Worksheet

Set ws = ActiveSheet

root = "C:\"
ws.Range("A:A").Clear

sFileName = Dir(root & "*.XLS")
Do While sFileName < ""
index = index + 1
ws.Cells(index, 1) = sFileName
CopySheets sFileName
ActiveSheet.Name = "Sheet_" & index ''NEW LINE
sFileName = Dir()
Loop

MsgBox ("Completed Copying")
End Sub
Sub CopySheets(sFileName As String)
Dim wb As Workbook
Set wb = Workbooks.Open(root & sFileName)
ActiveWindow.WindowState = xlNormal
wb.Sheets(1).Copy Befo=ThisWorkbook.Sheets(1)
wb.Close False
End Sub

I now want a seperate macro that can delete all of these new sheets.

Somebody has told me to use:-
Application.DisplayAlerts=False
worksheets(n).Delete
Application.DisplayAlerts=True

but I can't seem to just paste this into a new macro.

Any help would be greatly appreciated!


---
Message posted from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Delete new sheets?

No, you would have to introduce the code into a macro similar to the one you
have. The code provided just shows how to delete a sheet (sheet n in the
tab order) without prompt. You still need code like you have to open the
workbooks and identify which workbooks to delete the sheet in.

--
Regards,
Tom Ogilvy

ianripping wrote in message
...
I have this macro which copies all of the 1st sheets from any excel
files in my c:\ directory.

Option Explicit
Private root As String
Sub ListFiles()
Dim sFileName As String
Dim index As Long
Dim ws As Worksheet

Set ws = ActiveSheet

root = "C:\"
ws.Range("A:A").Clear

sFileName = Dir(root & "*.XLS")
Do While sFileName < ""
index = index + 1
ws.Cells(index, 1) = sFileName
CopySheets sFileName
ActiveSheet.Name = "Sheet_" & index ''NEW LINE
sFileName = Dir()
Loop

MsgBox ("Completed Copying")
End Sub
Sub CopySheets(sFileName As String)
Dim wb As Workbook
Set wb = Workbooks.Open(root & sFileName)
ActiveWindow.WindowState = xlNormal
wb.Sheets(1).Copy Befo=ThisWorkbook.Sheets(1)
wb.Close False
End Sub

I now want a seperate macro that can delete all of these new sheets.

Somebody has told me to use:-
Application.DisplayAlerts=False
worksheets(n).Delete
Application.DisplayAlerts=True

but I can't seem to just paste this into a new macro.

Any help would be greatly appreciated!


---
Message posted from http://www.ExcelForum.com/



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-delete all sheets except puiuluipui Excel Discussion (Misc queries) 6 October 13th 09 05:49 AM
FORMULA TO DELETE A ROW IN LINKED SHEETS Care New Users to Excel 1 June 26th 07 03:33 PM
Macro to delete unwanted sheets Sal Excel Discussion (Misc queries) 5 March 15th 07 09:33 PM
How do I delete Sheets if "Delete" is greyed out? carriemca Excel Discussion (Misc queries) 1 April 10th 06 05:31 PM
select and delete sheets Locachica Excel Programming 5 December 31st 03 01:02 PM


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