PDA

View Full Version : Check my work...


alaskalonewolf
01-09-2009, 03:37 PM
Figured since we were going for a cry for help,
then I might as well start howling myself.
I know, I know, I should be able to
fend for myself at this point...

...but oh well, what I really need is less
caffeine (http://en.wikipedia.org/wiki/Caffeine) in my diet and
more sleep (http://en.wikipedia.org/wiki/Sleep).

I've been trying to manage data for
the possibility of processing and
searching through huge blocks
of email using a macro in
outlook, to table it in
excel. Dunno where
I goofed... help plz?

[original context (http://blogs.techrepublic.com.com/msoffice/?p=744)]

//the following didn't work... plz take pity on my noobishness

Sub ExportToExcel()
On Error GoTo ErrHandler
Dim appExcel As Excel.Application Dim wkb As Excel.Workbook

Dim wks As Excel.Worksheet

Dim rng As Excel.Range

Dim strSheet As String

Dim strPath As String

Dim intRowCounter As Integer

Dim intColumnCounter As Integer

Dim msg As Outlook.MailItem

Dim nms As Outlook.NameSpace

Dim fld As Outlook.MAPIFolder

Dim itm As Object
strSheet = "OutlookItems.xls" strPath = "C:Examples\"

strSheet = strPath & strSheet

Debug.Print strSheet
'Select export folder
Set nms = Application.GetNamespace("MAPI")

Set fld = nms.PickFolder
'Handle potential errors with Select Folder dialog box.
If fld Is Nothing Then

MsgBox "There are no mail messages to export", vbOKOnly, _

"Error"

Exit Sub

ElseIf fld.DefaultItemType <> olMailItem Then

MsgBox "There are no mail messages to export", vbOKOnly, _

"Error"

Exit Sub

ElseIf fld.Items.Count = 0 Then

MsgBox "There are no mail messages to export", vbOKOnly, _

"Error"

Exit Sub

End If
'Open and activate Excel workbook.
Set appExcel = CreateObject("Excel.Application")

appExcel.Workbooks.Open (strSheet)

Set wkb = appExcel.ActiveWorkbook

Set wks = wkb.Sheets(1)

wks.Activate

appExcel.Application.Visible = True
'Copy field items in mail folder.
For Each itm In fld.Items

intColumnCounter = 1

Set msg = itm

intRowCounter = intRowCounter + 1

Set rng = wks.Cells(intRowCounter, intColumnCounter)

rng.Value = msg.To

intColumnCounter = intColumnCounter + 1

Set rng = wks.Cells(intRowCounter, intColumnCounter)

rng.Value = msg.SenderEmailAddress

intColumnCounter = intColumnCounter + 1

Set rng = wks.Cells(intRowCounter, intColumnCounter)

rng.Value = msg.Subject

intColumnCounter = intColumnCounter + 1

Set rng = wks.Cells(intRowCounter, intColumnCounter)

rng.Value = msg.SentOn

intColumnCounter = intColumnCounter + 1

Set rng = wks.Cells(intRowCounter, intColumnCounter)

rng.Value = msg.ReceivedTime

Set rng = wks.Cell(intRowCounter, intColumnCounter)

rng.Value = msg.Body

intColumnCounter = intColumnCounter + 1

If msg.field <> “” Then rng.Value = msg.field

Next itm
Set appExcel = Nothing Set wkb = Nothing

Set wks = Nothing

Set rng = Nothing

Set msg = Nothing

Set nms = Nothing

Set fld = Nothing

Set itm = Nothing
Exit Sub
ErrHandler: If Err.Number = 1004 Then

MsgBox strSheet & " doesn't exist", vbOKOnly, _

"Error"

Else

MsgBox Err.Number & "; Description: ", vbOKOnly, _

"Error"

End If

Set appExcel = Nothing

Set wkb = Nothing

Set wks = Nothing

Set rng = Nothing

Set msg = Nothing

Set nms = Nothing

Set fld = Nothing

Set itm = Nothing
End Sub

_____________________________________________//end of script

alaskalonewolf
01-09-2009, 07:45 PM
[crickets] ...took a nap, figured a ninja would swoop in...


c'mon ninjas...



[crickets]


c'mon ninjas...

concepttranquility
01-17-2009, 05:56 AM
I do a lot more web based coding than I do high-level programming. However your syntax seems to be right so the only thing I could imagine is the procedure is wrong. I don't have Visual Basic installed only Delphi, so I can't really compile it and see...

However I would have to say I noticed one thing: "C:Examples/" Which should be "C:/Examples" correct? If you're not outputting them correctly it wouldn't be able to even save it or read it because that path doesn't exist.

I haven't really taken into consideration how your code works just looked at syntax. Good luck.

hickslayer
01-17-2009, 12:36 PM
whoah ninja. turn right at the green arrow. don't take this as a joke.


plz advise

alaskalonewolf
02-03-2009, 09:44 PM
No seriously. I was wondering if anyone actually uses this Outlook to Excel app?

...and I was curious if same, had ever used:

http://sourceforge.net/projects/andro/

If you have, hit me up elsewhere:

http://sourceforge.net/users/alaskalonewolf

Don't wanna waste this space.
It's probably not the right forum
all things considered...

...don't take as a joke.
[That is all.]