Microsoft Office Tutorials and References
In Depth Information
Transferring Data from E-mail Attachments to Excel
'Set target worksheet¶
'It is supposed to be the first worksheet¶
'So using index 1¶
Set shtTarget = wrkTarget.Worksheets(1)¶
'Source data is supposed to be in column B¶
'B1:B5 range in sample workbook¶
Set rngSource = shtSource.Range("$B$1:$B$5")¶
'Target cell is the next empty cell¶
'in target worksheet's column A¶
'xlUp = -4162¶
Set rngTarget = shtTarget.Cells(65536, 1) _¶
.End(-4162).Offset(1)¶
'Loop through source data cells¶
For Each cll In rngSource.Cells¶
With rngTarget¶
'Transfer data into corresponding column¶
'Data order is trasposed version of source range¶
.Cells(1, cll.Row).Value = cll.Value¶
End With¶
Next cll¶
'Close workbook objects and free memory¶
wrkSource.Close False¶
wrkTarget.Close True¶
'Delete temporary source workbook¶
Kill strSourceFile¶
ExitSub:¶
'Quit Excel Application that has been¶
'created in this code¶
If Not xlsApp Is Nothing Then¶
xlsApp.Quit¶
End If¶
Exit Sub¶
ErrorHandler:¶
'Critical error¶
MsgBox Err.Number & "-" & Err.Description, _¶
vbOKOnly + vbExclamation, "Error"¶
GoTo ExitSub¶
End Sub¶
Cmb
The first code section goes in the class module ThisOutlookSession. The second
code section goes in the class module clsFolderEvents.
Note: The strTargetFile: "C:\O006.xls" and the strFileName: “O006-1.xls” should be
changed to the desired path and name of the Excel file that stores the data.
This macro runs automatically.
To test this sample code, follow these steps:
Search JabSto ::




Custom Search