Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Add files to ZIP using VBA

Hi hope someone can help me out
The code below will ZIP the active workbook and send the zip file via email

1. I need to insert addition files into the ZIP archive before it hits the
email
2. I need Outlook to setup the email but NOT send the file (ie I'd like to
manually press send...)

Any ideas much appeciated



Sub ActiveWorkbook_Zip_Mail()
'This sub will send a newly created workbook (copy of the Activeworkbook).
'It zip and save the workbook before mailing it with a date/time stamp.
'After the zip file is sent the zip file and the workbook will be deleted
from your hard disk.
Dim PathWinZip As String, FileNameZip As String, FileNameXls As String
Dim ShellStr As String, strdate As String
Dim Runwzzip As Long
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem

PathWinZip = "C:\program files\winzip\"
'This will check if this is the path where WinZip is installed.
If Dir(PathWinZip & "winzip32.exe") = "" Then
MsgBox "Please find your copy of winzip32.exe and try again"
Exit Sub
End If

esaName = ActiveSheet.Range("f6").Value
seqNumber = ActiveSheet.Range("b6").Value
FileNameZip = "C:\rds\zipped\" & seqNumber & " " & esaName & ".zip "
FileNameXls = "C:\rds\zipped\" & seqNumber & " " & esaName & ".xls"
ActiveWorkbook.SaveCopyAs FileName:=FileNameXls

ShellStr = PathWinZip & "Winzip32 -min -a " _
& " " & Chr(34) & FileNameZip & Chr(34) _
& " " & Chr(34) & FileNameXls & Chr(34)
Runwzzip = Shell(ShellStr, vbHide)


nSubject = ActiveSheet.Range("b6").Value
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)

With OutMail
.To = "Email here"
.CC = ""
.BCC = ""
.Subject = nSubject
.Body = " "
.Attachments.Add FileNameZip
.Send


End With

Set OutMail = Nothing
Set OutApp = Nothing
Kill FileNameXls

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Add files to ZIP using VBA

Hi Steve,

1.You could try iterating through a collection of files passing the same Shell command, this will add each to the archive.

Something like:
Using FSO.Getfolder, you can collect all of the fso.files and add them into your collection. So if all of the workbooks are in the same folder, you can just iterate through the folder contents to get each of the files.

2. To have your created email displayed instead of sent, you just use, .display (instead of .send) in you olMessage code. This will then show the email before you send it.

Tip: With the error handling for the winzip.exe file, you can use Application.GetOpenFileName, which then you can trap & filter the file that is selected. Although this is passed through excel, you just wouldn't use the Execute Command.

I.e.
Dim strWinZip as String
strWinZip = Application.GetOpenFilename "Application Files (*.exe), *.exe"
if strWinZip = False or strWinZip = "" then
..........
else
'Use StrWinzip as the location where your file was found. Remember that strWinZip is a String.
end if

----- Steve wrote: -----

Hi hope someone can help me out
The code below will ZIP the active workbook and send the zip file via email

1. I need to insert addition files into the ZIP archive before it hits the
email
2. I need Outlook to setup the email but NOT send the file (ie I'd like to
manually press send...)

Any ideas much appeciated



Sub ActiveWorkbook_Zip_Mail()
'This sub will send a newly created workbook (copy of the Activeworkbook).
'It zip and save the workbook before mailing it with a date/time stamp.
'After the zip file is sent the zip file and the workbook will be deleted
from your hard disk.
Dim PathWinZip As String, FileNameZip As String, FileNameXls As String
Dim ShellStr As String, strdate As String
Dim Runwzzip As Long
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem

PathWinZip = "C:\program files\winzip\"
'This will check if this is the path where WinZip is installed.
If Dir(PathWinZip & "winzip32.exe") = "" Then
MsgBox "Please find your copy of winzip32.exe and try again"
Exit Sub
End If

esaName = ActiveSheet.Range("f6").Value
seqNumber = ActiveSheet.Range("b6").Value
FileNameZip = "C:\rds\zipped\" & seqNumber & " " & esaName & ".zip "
FileNameXls = "C:\rds\zipped\" & seqNumber & " " & esaName & ".xls"
ActiveWorkbook.SaveCopyAs FileName:=FileNameXls

ShellStr = PathWinZip & "Winzip32 -min -a " _
& " " & Chr(34) & FileNameZip & Chr(34) _
& " " & Chr(34) & FileNameXls & Chr(34)
Runwzzip = Shell(ShellStr, vbHide)


nSubject = ActiveSheet.Range("b6").Value
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)

With OutMail
.To = "Email here"
.CC = ""
.BCC = ""
.Subject = nSubject
.Body = " "
.Attachments.Add FileNameZip
.Send


End With

Set OutMail = Nothing
Set OutApp = Nothing
Kill FileNameXls

End Sub



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
Navigating to Excel files over network slow, but not Word files Newbie123 Excel Discussion (Misc queries) 1 December 2nd 09 01:18 PM
How can I batch convert 97-2003 .xls files to 2007 .xlsx files Dave Nuttall Excel Discussion (Misc queries) 4 August 3rd 09 11:38 PM
How to change default Open/Files of Type to "Microsoft Excel Files Tammy Excel Discussion (Misc queries) 2 January 14th 08 11:06 PM
converter tool to convert XL 2007 files to XL 2003 files Dave F Excel Discussion (Misc queries) 6 December 15th 06 12:45 AM
Drive Erased, got Files back but only excel files scrambled, help. Shawnky Excel Discussion (Misc queries) 0 May 8th 06 07:26 PM


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