Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, What I currently do is create a

Status
Not open for further replies.

yumbelie

Programmer
Dec 31, 2002
96
0
0
GB
Hi, What I currently do is create a new workbook, copy the sheet 'snapshot' to the new workbook, delete 'sheet1' in the new workbook (for the asthetics), save the work book and exit. Problem is, when the code removes sheet1 it prompts to confirm, I don't want it to do this - and I can't quite figure out what you need to put it so it doesn't issue a prompt.

Private Sub CommandButton3_Click()

Dim Response As String
Dim datestring As String
Dim filename As String
Dim path As String

Set MyWorkbook = ActiveWorkbook
Set MySheet = ActiveWorkbook.Worksheets("Patient Delay")
Dim SnapshotSheet As Object
Set SnapshotSheet = CreateObject("Excel.Sheet")

datestring = (Trim(Str(Day(Now())) + "-" + Str(Month(Now())) + "-" + Str(Year(Now()))))
path = "C:\"
filename = path + "Snapshot " + datestring + ".xls"
Response = MsgBox(filename)

MyWorkbook.Sheets("Snapshot").Select
MyWorkbook.Sheets("Snapshot").Copy After:=SnapshotSheet.Worksheets("Sheet1")
SnapshotSheet.Sheets("Sheet1").Select
ActiveWindow.SelectedSheets.Delete

SnapshotSheet.SaveAs (filename)
MyWorkbook.Sheets("Patient Delay").Activate

End Sub

Thats the code - Any help appericated guys :)
 
Swith off display alerts at the beginning of your routine and switch back on at the end ie

Code:
Application.displayalerts = false/true

It's snowing in London (incase you don't realise, that NEVER happens!!)

;-) If a man says something and there are no women there to hear him, is he still wrong?
 
Application.DisplayAlerts = False
ActiveWindow.SelectedSheets.Delete
Application.DisplayAlerts = True

Look up DisplayAlerts in the help to get the full context.

Another good one is Application.ScreenUpdating. Set it to false and you won't see the macro bouncing around the sheets. Be sure to set it back to true at the end of the macro or in your error handling.

Patrick
 
You can also, instead of creating the new workbook and then copying, simply use:

MyWorkbook.Sheets("Snapshot").Copy

This will create a new workbook with just one worksheet, which I think is just what you want.
Rob
[flowerface]
 
I have just added an additional sheet copy request over, so it copies Snapshot1 and Snapshot2 to a new sheet, then supposed to delete sheet1 and vanish. Problem is now if you issue the 'delete sheet1' statement, it seems to delete all the sheets. Any ideas?
 
I'm using ActiveSheet.Delete after selecting the sheet I want removed. I'll paste the code in again:

MyWorkbook.Sheets("Snapshot - MDT").Select
MyWorkbook.Sheets("Snapshot - MDT").Copy After:=SnapshotSheet.Worksheets("Sheet1")
MyWorkbook.Activate
MyWorkbook.Sheets("Snapshot - DTC").Select
MyWorkbook.Sheets("Snapshot - DTC").Copy After:=SnapshotSheet.Worksheets("Sheet1")

'SnapshotSheet.Sheets("Sheet1").Select Replace:=True
SnapshotSheet.Sheets("Sheet1").Select
ActiveSheet.Delete

SnapshotSheet.SaveAs (filename)
MyWorkbook.Sheets("Patient Delay").Activate

Application.DisplayAlerts = True
 
try this to do the job:

dim CopySheets(1 to 2) as string
CopySheets(1)="Snapshot - MDT"
CopySheets(2)="Snapshot - DTC"
sheets(CopySheets).copy
activeworkbook.saveas filename
MyWorkbook.activate
Sheets("Patient Delay").Activate
Rob
[flowerface]
 
Pardon me for butting in so late, but I can't help wondering... Why not just rename the sheet?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top