New to OL VBA: What returns "ThisMessage"?

  • Thread starter Thread starter Ed
  • Start date Start date
E

Ed

I've done VBA in Word and Excel, but not Outlook. I regularly send emails
in which I must attach one or more Word docs. The problem is that these
docs are in a folder of over 13,000 docs; when I click "InsertFile", it can
take quite a while for all the docs to load into the dialog box window. I
thought I'd try a macro which would open an InputBox for the file name, then
programmatically add the attachment faster than waiting for the window to
load up. (Using XP, by the way.)

I've been through the Object Browser, though, in the VBE, and can't seem to
identify the phrase for the email message I have opened. I can see where to
create a new one, but I don't want that. Something equivalent to Word's
ActiveDocument or Excel's ThisWorkbook?

Or am I thinking all wrong on this? Any help is appreciated. (And doesn't
OL have a macro recorder?)

Ed
 
No macro recorder.

Application.ActiveInspector.CurrentItem is what's opened and has focus.
Inspectors are used to display open items.

Look at the VBA pages at www.outlookcode.com for lots to get you started
with Outlook programming.
 
Try Application.ActiveInspector.CurrentItem for the currently open item.
 
Thank you, Ken. I appreciate the help.

Ed

Ken Slovak - said:
No macro recorder.

Application.ActiveInspector.CurrentItem is what's opened and has focus.
Inspectors are used to display open items.

Look at the VBA pages at www.outlookcode.com for lots to get you started
with Outlook programming.




where
 
Ken - Built this, but it errors - "Can't find this file". I know the file
path (strAtt) is good, so I'm thinking I've either mis-wrote the objAtt.Add
statement, or this doesn't support using the wildcard " * " in strFName.
What do you think?

Ed

Sub AttachFile()

Dim objMail As Outlook.MailItem
Dim objAtt As Outlook.Attachments
Dim strVeh As String
Dim strFName As String
Dim strAtt As String

Set objMail = Application.ActiveInspector.CurrentItem
Set objAtt = objMail.Attachments

strVeh = InputBox("Enter the three-letter vehicle designator", _
"File to attach", "MGS")

strFName = InputBox("Enter the file name", "File to attach")
strFName = " * " & strFName & ".doc"

strAtt = "C:\Documents and Settings\myname\Desktop\" & _
"Vehicle Reports\Vehicle " & strVeh & "\" & _
strVeh & " Reports\" & strFName

MsgBox strAtt

' On Error Resume Next
objAtt.Add strAtt, olByValue ' wasn't sure which Type to use, so I picked
this one

Set objMail = Nothing
Set objAtt = Nothing

End Sub
 
Back
Top