Da proverim da li sam shvatio sta zelis da uradis:
1. Nalazis se u Outlook-u i citas neki email
2. Radis Reply
3. Automatski treba da se zakaci novi excel fajl kao atachment
Evo koda koji radi upravo gore pomenuto - Reply With New Excel Workbook sto bi se reklo ;-)
Kod je napravljen po ugledu na
http://www.outlookcode.com/codedetail.aspx?id=1228
koji radi reply sa svim postojecim prilozima (slicno funkcionisanju forward komande)
Code:
Dim wb As New Excel.Workbook
Sub ReplyWithExcelAttachment()
Dim rpl As Outlook.MailItem
Dim itm As Object
Set itm = GetCurrentItem()
If Not itm Is Nothing Then
Set rpl = itm.Reply
Set wb = Workbooks.Add
Set fso = CreateObject("Scripting.FileSystemObject")
Set fldTemp = fso.GetSpecialFolder(2) ' TemporaryFolder
strPath = fldTemp.Path & "\"
strFile = strPath & "newbook.xls"
wb.SaveAs strFile
wb.Close
rpl.Attachments.Add strFile, , , "newbook.xls"
fso.DeleteFile strFile
rpl.Display
End If
Set wb = Nothing
Set rpl = Nothing
Set itm = Nothing
End Sub
Function GetCurrentItem() As Object
Dim objApp As Outlook.Application
Set objApp = Application
On Error Resume Next
Select Case TypeName(objApp.ActiveWindow)
Case "Explorer"
Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
End Select
Set objApp = Nothing
End Function
Dodaj novi modul u Outlooku i ubaci ovaj kod.
Za odabranu poruku pozovi ReplyWithExcelAttachment.
Napomena: dodaj referencu ka Microsoft Excel xx Object Library (gde je xx verzija koju imas instaliranu).
Pozdrav