Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-30-2013, 10:11 AM
Cait783 Cait783 is offline Help with Excel Macro Windows XP Help with Excel Macro Office 2010 32bit
Novice
Help with Excel Macro
 
Join Date: Mar 2013
Posts: 1
Cait783 is on a distinguished road
Default Help with Excel Macro

I've copied this macro from a coworker and I need to change it so that it will send the (most current) file that I just edited as an attachment in the email that the macro is already sending out. The macro saves the current file in a specific folder with just a time stamp to seperate the files. I know next to nothing about macros so any help would be greatly apreciated.
Code:
Sub Mail_Picking_Outlook() 'Working in 2000-2010 Dim wb1 As Workbook Dim wb2 As Workbook Dim FilePath As String Dim FileName As String Dim FileExtStr As String Dim OutApp As Object Dim OutMail As Object Set wb1 = ActiveWorkbook If Val(Application.Version) >= 12 Then If wb1.FileFormat = 51 And wb1.HasVBProject = True Then MsgBox "There is VBA code in this xlsx file, there will" & vbNewLine & _ "be no VBA code in the file you send. Save the" & vbNewLine & _ "file first as xlsm and then try the macro again.", vbInformation Exit Sub End If End If With Application .ScreenUpdating = False .EnableEvents = False End With 'Make a copy of the file/Open it/Mail it/Delete it 'If you want to change the file name then change only FileName FilePath = "m:\Picking\Completed Forms\" FileName = Range("A1") & " Picking " & Range("B34") FileExtStr = "." & LCase(Right(wb1.Name, _ Len(wb1.Name) - InStrRev(wb1.Name, ".", , 1))) wb1.SaveCopyAs FilePath & FileName & FileExtStr Set wb2 = Workbooks.Open(FilePath & FileName & FileExtStr) Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(0) On Error Resume Next With OutMail .to = "email@email.org" .CC = "" .BCC = "" .Subject = Range("A1") & " Picking " & Range("B34") .Body = Range("A1") & " Picking " & Range("B34") .Attachments.Add wb2.FullName 'You can add other files also like this '.Attachments.Add ("C:\test.txt") .Send 'or use .Display End With On Error Goto 0 wb2.Close SaveChanges:=False Set OutMail = Nothing Set OutApp = Nothing MsgBox "1. File has been e-mailed to XYZ at " & Format(Now, "[$409]hh:mm:ss AM/PM") & " on " & Format(Now, "mmm-dd-yyyy") & "." & vbNewLine & "2. The file is also saved to the server as: " & vbNewLine & Format(Now, "yyyymmdd-hhmmss ") & Range("A1") With Application .ScreenUpdating = True .EnableEvents = True End With End Sub


Last edited by macropod; 03-31-2013 at 11:24 PM. Reason: Added code tags & formatting
Reply With Quote
  #2  
Old 03-31-2013, 11:31 PM
macropod's Avatar
macropod macropod is offline Help with Excel Macro Windows 7 64bit Help with Excel Macro Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Cait783,

From my reading of the code, it saves the workbook, then sends it as an attachment. In that case, the attachment should always be the most recent file in the folder. In other words, it already does what you say you want it to.

PS: When posting code, please post formatted code, using the code tags. They're on the 'Go Advanced' tab.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
vba excel



Similar Threads
Thread Thread Starter Forum Replies Last Post
using macro or vba in excel jassie Excel Programming 1 03-22-2012 10:39 PM
Help with Excel Macro Macro Excel Il_Fabietto Excel Programming 3 07-28-2011 02:40 AM
Macro: chart from excel into PP as objects Jazz43 PowerPoint 0 03-05-2011 09:06 AM
Help with Excel Macro Excel macro (vba) HuaMin Excel 2 03-22-2010 08:11 PM
Help with Excel Macro Help! for using an appropriate function/Macro in Excel pawan2paw Excel 1 06-04-2009 12:28 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:41 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft