LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
JK JK is offline
external usenet poster
 
Posts: 10
Default Insert FileName - TabName and Date() - using VBA

I found this great bit of code online. This automatically creates an email
and adds the selected worksheet (only the worksheet) as an attachment. What
I'd like to do is where is says FileName = "Temp.xls" change that to the
following:

"Weekly.Purchase.Summary_TABNAME_DATE().xls"

I'd like to inclulde the tab name and todays date (whever it's being emailed.)

Is this possible?

Thanks so much for your help; the code is pasted below.

Happy New Year!!!

Sub EmailWithOutlook()
'Variable declaration
Dim oApp As Object, _
oMail As Object, _
WB As Workbook, _
FileName As String

'Turn off screen updating
Application.ScreenUpdating = False

'Make a copy of the active sheet and save it to
'a temporary file
ActiveSheet.Copy
Set WB = ActiveWorkbook
FileName = "Temp.xls"
On Error Resume Next
Kill "C:\" & FileName
On Error GoTo 0
WB.SaveAs FileName:="C:\" & FileName

'Create and show the outlook mail item
Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItem(0)
With oMail
'Uncomment the line below to hard code a recipient
.To = ; ;
"
'Uncomment the line below to hard code a subject
.Subject = "Weekly Purchase Summary"
.Attachments.Add WB.FullName
.Display
End With

'Delete the temporary file
WB.ChangeFileAccess Mode:=xlReadOnly
Kill WB.FullName
WB.Close SaveChanges:=False

'Restore screen updating and release Outlook
Application.ScreenUpdating = True
Set oMail = Nothing
Set oApp = Nothing
End Sub
 
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
set filename to <filename-date on open bob engler Excel Worksheet Functions 2 July 13th 06 05:11 AM
set excel <filename to <filename-date bob engler Excel Programming 2 July 12th 06 08:22 AM
Tabname Changes Big Rick Excel Discussion (Misc queries) 2 March 2nd 06 05:31 PM
Retreiving TABNAME from within a spreadsheet Bob Harike Excel Discussion (Misc queries) 2 February 2nd 05 09:35 PM
Insert value of a cell as a filename Ralph Howarth Excel Worksheet Functions 0 January 18th 05 12:03 AM


All times are GMT +1. The time now is 06:13 PM.

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"