View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
stevebriz stevebriz is offline
external usenet poster
 
Posts: 195
Default filename in "Subject" in email

As the FName is declared in a different sub to your mail sub the
calue does not pass. If you declare in one sub this only applies to
the procedure its declared in.
You need to declare it either in the declarations section above your
code in the module if both procedures ( determine the value of FName
and the Sub Mail_Selection_Outlook_Body()) are in the same module or
declare it as Public Fname As Variant in the declarations section of a
Module.
Hope this is not too confusing!
Helmut wrote:
Hi I have:

Dim Fname As Variant

Fname = Application.GetSaveAsFilename("c:\MESSER\" &
Range("mesnum").Value & "_" & Replace(Range("filedate").Value, "/", "") &
".csv")

This works well, then: note the .Subject line...I am trying to use the Fname
from above in the Subject line. How is that possible? right now I get the
rest but not the Fname

Sub Mail_Selection_Outlook_Body()
' You must add a reference to the Microsoft outlook Library
' Don't forget to copy the function RangetoHTML in the module.

Dim sh As Worksheet
Dim rng As Range
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem

'If you know the sheet/range then use this two lines
Set sh = Sheets("START")
Set rng = sh.Range("head")

Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = "
.CC = ""
.BCC = "
.Subject = Fname & "_" & " now is in \\Cav_New\Files"
.HTMLBody = RangetoHTML(sh, rng)
.Send 'or use .Display
End With
Set OutMail = Nothing
Set OutApp = Nothing
Application.ScreenUpdating = True