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

Hi,

I have a selection of code that currently makes a copy of the exsisting
workbook and then zips and emails that copy using Outlook, I know this might
sound hopeful but is it at all possible to delete a worksheet out of the copy
before it gets zipped and emailed.

Thanks
Phil
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rob Rob is offline
external usenet poster
 
Posts: 718
Default Copy & Delete

try:

Thisworkbook.savecopyas "NewFileName.xls"
Set NewBook=workbooks("NewFileName.xls").open
with newbook
application.displayalerts=false
.sheets("sheetName").delete
application.displayalerts=true
end with
'then your code for e-mailing etc



"Phil" wrote:

Hi,

I have a selection of code that currently makes a copy of the exsisting
workbook and then zips and emails that copy using Outlook, I know this might
sound hopeful but is it at all possible to delete a worksheet out of the copy
before it gets zipped and emailed.

Thanks
Phil

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default Copy & Delete

Just to let you know I have managed to get it to compile further, it was
missing the s of workbooks, now it's just getting a Method or Data error on
..Sheets, slowly getting there, as you can tell this is my first time using VB.

Thanks Phil

"Phil" wrote:

Hi Rob,

Thanks again for the quick reply, I had already set up the variable and
defined the whole path, this is what my code looks like at the moment : -

Sub ActiveWorkbook_Zip_Mail()

Dim PathWinZip As String, FileNameZip As String, FileNameXls As String,
Route As String, Newbook As Workbook
Dim ShellStr As String, strDate As String
Dim OutApp As Object
Dim OutMail As Object

PathWinZip = "C:\program files\ezip wizard\"

If Dir(PathWinZip & "eZip32.exe") = "" Then
MsgBox "Please find your copy of ezip32.exe and try again"
Exit Sub
End If

sendTo = Range("B24").Value

'ActiveWorkbook.SaveCopyAs Filename:="c:\test\Copy.xls"

'Sheets(Hope & "Copy.xls" & "Sheet5").Delete

ThisWorkbook.SaveCopyAs "c:\test\copy.xls"
Set Newbook = Workbook("c:\test\copy.xls").Open
With Newbook
Application.DisplayAlerts = False
.Sheets("sheet5").Delete
Application.DisplayAlerts = True
End With

Route = "c:\test"

FileNameZip = Route & "\" & "Copy.zip"

FileNameXls = Route & "\" & "Copy.xls"

ShellStr = PathWinZip & "ezip32 -min -a" _
& " " & Chr(34) & FileNameZip & Chr(34) _
& " " & Chr(34) & FileNameXls & Chr(34)
ShellAndWait ShellStr, vbHide

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = sendTo
.CC = ""
.BCC = ""
.Subject = "IRVSData Check"
.Body = "Please find attached you latest cleansed file details"
.Attachments.Add FileNameZip
.Send
End With
Set OutMail = Nothing
Set OutApp = Nothing

Kill FileNameZip
Kill FileNameXls
End Sub


Thanks again for all the help, Phil

"Rob" wrote:

you need to declare the variable. Also "NewFileName.xls" should be the full
path where you are saving the workbook.

dim NewBook as workbook


Thisworkbook.savecopyas "NewFileName.xls"
Set NewBook=workbooks("NewFileName.xls").open
with newbook
application.displayalerts=false
.sheets("sheetName").delete
application.displayalerts=true
end with
'then your code for e-mailing etc


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default Copy & Delete

Hi Rob,

Thanks again for the quick reply, I had already set up the variable and
defined the whole path, this is what my code looks like at the moment : -

Sub ActiveWorkbook_Zip_Mail()

Dim PathWinZip As String, FileNameZip As String, FileNameXls As String,
Route As String, Newbook As Workbook
Dim ShellStr As String, strDate As String
Dim OutApp As Object
Dim OutMail As Object

PathWinZip = "C:\program files\ezip wizard\"

If Dir(PathWinZip & "eZip32.exe") = "" Then
MsgBox "Please find your copy of ezip32.exe and try again"
Exit Sub
End If

sendTo = Range("B24").Value

'ActiveWorkbook.SaveCopyAs Filename:="c:\test\Copy.xls"

'Sheets(Hope & "Copy.xls" & "Sheet5").Delete

ThisWorkbook.SaveCopyAs "c:\test\copy.xls"
Set Newbook = Workbook("c:\test\copy.xls").Open
With Newbook
Application.DisplayAlerts = False
.Sheets("sheet5").Delete
Application.DisplayAlerts = True
End With

Route = "c:\test"

FileNameZip = Route & "\" & "Copy.zip"

FileNameXls = Route & "\" & "Copy.xls"

ShellStr = PathWinZip & "ezip32 -min -a" _
& " " & Chr(34) & FileNameZip & Chr(34) _
& " " & Chr(34) & FileNameXls & Chr(34)
ShellAndWait ShellStr, vbHide

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = sendTo
.CC = ""
.BCC = ""
.Subject = "IRVSData Check"
.Body = "Please find attached you latest cleansed file details"
.Attachments.Add FileNameZip
.Send
End With
Set OutMail = Nothing
Set OutApp = Nothing

Kill FileNameZip
Kill FileNameXls
End Sub


Thanks again for all the help, Phil

"Rob" wrote:

you need to declare the variable. Also "NewFileName.xls" should be the full
path where you are saving the workbook.

dim NewBook as workbook


Thisworkbook.savecopyas "NewFileName.xls"
Set NewBook=workbooks("NewFileName.xls").open
with newbook
application.displayalerts=false
.sheets("sheetName").delete
application.displayalerts=true
end with
'then your code for e-mailing etc


  #5   Report Post  
Posted to microsoft.public.excel.programming
Rob Rob is offline
external usenet poster
 
Posts: 718
Default Copy & Delete

Sorry Phil. The line should be
set newbook=workbooks.open("c:\test\copy.xls")

"Phil" wrote:

Just to let you know I have managed to get it to compile further, it was
missing the s of workbooks, now it's just getting a Method or Data error on
.Sheets, slowly getting there, as you can tell this is my first time using VB.

Thanks Phil

"Phil" wrote:

Hi Rob,

Thanks again for the quick reply, I had already set up the variable and
defined the whole path, this is what my code looks like at the moment : -

Sub ActiveWorkbook_Zip_Mail()

Dim PathWinZip As String, FileNameZip As String, FileNameXls As String,
Route As String, Newbook As Workbook
Dim ShellStr As String, strDate As String
Dim OutApp As Object
Dim OutMail As Object

PathWinZip = "C:\program files\ezip wizard\"

If Dir(PathWinZip & "eZip32.exe") = "" Then
MsgBox "Please find your copy of ezip32.exe and try again"
Exit Sub
End If

sendTo = Range("B24").Value

'ActiveWorkbook.SaveCopyAs Filename:="c:\test\Copy.xls"

'Sheets(Hope & "Copy.xls" & "Sheet5").Delete

ThisWorkbook.SaveCopyAs "c:\test\copy.xls"
Set Newbook = Workbook("c:\test\copy.xls").Open
With Newbook
Application.DisplayAlerts = False
.Sheets("sheet5").Delete
Application.DisplayAlerts = True
End With

Route = "c:\test"

FileNameZip = Route & "\" & "Copy.zip"

FileNameXls = Route & "\" & "Copy.xls"

ShellStr = PathWinZip & "ezip32 -min -a" _
& " " & Chr(34) & FileNameZip & Chr(34) _
& " " & Chr(34) & FileNameXls & Chr(34)
ShellAndWait ShellStr, vbHide

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = sendTo
.CC = ""
.BCC = ""
.Subject = "IRVSData Check"
.Body = "Please find attached you latest cleansed file details"
.Attachments.Add FileNameZip
.Send
End With
Set OutMail = Nothing
Set OutApp = Nothing

Kill FileNameZip
Kill FileNameXls
End Sub


Thanks again for all the help, Phil

"Rob" wrote:

you need to declare the variable. Also "NewFileName.xls" should be the full
path where you are saving the workbook.

dim NewBook as workbook


Thisworkbook.savecopyas "NewFileName.xls"
Set NewBook=workbooks("NewFileName.xls").open
with newbook
application.displayalerts=false
.sheets("sheetName").delete
application.displayalerts=true
end with
'then your code for e-mailing etc



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default Copy & Delete

Hi Rob,

Thanks again for the help with this, I have made the necessary change as
suggested and made a further change with the delete statement i.e. it did
have a full stop at the beginning of the like with the delete on it, I have
removed this as it didn't seem to work.

ThisWorkbook.SaveCopyAs "c:\test\copy.xls"
Set Newbook = Workbooks.Open("c:\test\copy.xls")
With Newbook
Application.DisplayAlerts = False
Sheets("Sheet1").Delete
Application.DisplayAlerts = True
End With

What I get now is if I run the code in the code view and press run, the new
file is created, then it goes back to the code view of the original file and
says Type mismatch on this line :-

Set Newbook = Workbooks.Open("c:\test\copy.xls")

Slowly driving me mad but thanks for the help though :-)


"Phil" wrote:

Just to let you know I have managed to get it to compile further, it was
missing the s of workbooks, now it's just getting a Method or Data error on
.Sheets, slowly getting there, as you can tell this is my first time using VB.

Thanks Phil

"Phil" wrote:

Hi Rob,

Thanks again for the quick reply, I had already set up the variable and
defined the whole path, this is what my code looks like at the moment : -

Sub ActiveWorkbook_Zip_Mail()

Dim PathWinZip As String, FileNameZip As String, FileNameXls As String,
Route As String, Newbook As Workbook
Dim ShellStr As String, strDate As String
Dim OutApp As Object
Dim OutMail As Object

PathWinZip = "C:\program files\ezip wizard\"

If Dir(PathWinZip & "eZip32.exe") = "" Then
MsgBox "Please find your copy of ezip32.exe and try again"
Exit Sub
End If

sendTo = Range("B24").Value

'ActiveWorkbook.SaveCopyAs Filename:="c:\test\Copy.xls"

'Sheets(Hope & "Copy.xls" & "Sheet5").Delete

ThisWorkbook.SaveCopyAs "c:\test\copy.xls"
Set Newbook = Workbook("c:\test\copy.xls").Open
With Newbook
Application.DisplayAlerts = False
.Sheets("sheet5").Delete
Application.DisplayAlerts = True
End With

Route = "c:\test"

FileNameZip = Route & "\" & "Copy.zip"

FileNameXls = Route & "\" & "Copy.xls"

ShellStr = PathWinZip & "ezip32 -min -a" _
& " " & Chr(34) & FileNameZip & Chr(34) _
& " " & Chr(34) & FileNameXls & Chr(34)
ShellAndWait ShellStr, vbHide

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = sendTo
.CC = ""
.BCC = ""
.Subject = "IRVSData Check"
.Body = "Please find attached you latest cleansed file details"
.Attachments.Add FileNameZip
.Send
End With
Set OutMail = Nothing
Set OutApp = Nothing

Kill FileNameZip
Kill FileNameXls
End Sub


Thanks again for all the help, Phil

"Rob" wrote:

you need to declare the variable. Also "NewFileName.xls" should be the full
path where you are saving the workbook.

dim NewBook as workbook


Thisworkbook.savecopyas "NewFileName.xls"
Set NewBook=workbooks("NewFileName.xls").open
with newbook
application.displayalerts=false
.sheets("sheetName").delete
application.displayalerts=true
end with
'then your code for e-mailing etc

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default Copy & Delete

Hi Rob,

After a lot of searching sites, I have finally got it all working, I'm
arfaid I hacked your original code up a bit and I'm not sure if this is the
best way to write it but it works....


ThisWorkbook.SaveCopyAs "c:\test\copy.xls"
Application.Workbooks.Open ("c:\test\copy.xls")
Application.DisplayAlerts = False
Sheets("Sheet1").Delete
ActiveWorkbook.Close savechanges:=True
Application.DisplayAlerts = True

Thanks for all the help, wouldn't of got this far otherwise.

Thanks Phil


"Phil" wrote:

Hi,

I have a selection of code that currently makes a copy of the exsisting
workbook and then zips and emails that copy using Outlook, I know this might
sound hopeful but is it at all possible to delete a worksheet out of the copy
before it gets zipped and emailed.

Thanks
Phil

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
Copy column header to next column, delete & delete every nth colum genehunter New Users to Excel 1 June 2nd 09 03:57 PM
Clear and Copy vs Delete Barry Lennox[_2_] Excel Discussion (Misc queries) 2 December 19th 08 08:46 PM
cut and delete a row then insert and copy lmch New Users to Excel 1 October 10th 07 11:38 AM
Copy & Delete Phil Excel Programming 1 April 21st 05 05:42 PM
Copy, Paste then delete Louise Excel Programming 2 March 22nd 05 03:41 AM


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