![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
![]() Full code appended below. My goal is that this code (when triggered) will allow the user to select a destination folder and enter a filename, and select a source outlook folder. The code should then scrape each email in that folder to get the sent date/time, the subject line, and the sender, and dump that info into a flat file (which will be used in Excel). (1) Apparently outlook doesn't have an application.filedialogue (code errors out in the function on this line). What is the best way to allow a user to select a destination folder for a generated file? Alternatively, is there a way to determine the path to the desktop and always save to the desktop, given that each user's path to the desktop will be unique? (2) I'll need my code to work in both Outlook 2003 and 2007. I don't have direct access to a 2007 box, but would welcome feedback if you see anything in this code that is likely to fail in 2007 Thank you! Keith Sub ParseAlertEmails() '(strSource As String, strLabel As String) Set myOlApp = CreateObject("Outlook.Application") Set olns = myOlApp.GetNamespace("MAPI") Set myinbox = olns.PickFolder Set myItems = myinbox.Items Dim fso, tf Set fso = CreateObject("Scripting.FileSystemObject") UseFolder = GetFolder UseDateApp = Format(Now(), "YYMMDDHHmmss") UseFN = InputBox("Please enter the name of the destination file", "Save As") Set tf = fso.CreateTextFile(UseFN & " " & UseDateApp, True) StartCount = 0 strEmailContents = "" For Each outlookmessage In myinbox.Items If IgnoreEmail = False Then strEmailContents = outlookmessage.ReceivedTime strEmailContents = strEmailContents & ";" & outlookmessage.sender strEmailContents = strEmailContents & ";" & outlookmessage.Subject tf.Write strEmailContents & vbCrLf End If strEmailContents = "" StartCount = StartCount + 1 Next tf.Close Set fso = Nothing Set myOlApp = Nothing Set olns = Nothing Set myinbox = Nothing Set myItems = Nothing End Sub Private Function GetFolder(Optional strPath As String) As String Dim fldr As FileDialog Dim sItem As String Set fldr = Application.FileDialog(msoFileDialogFolderPicker) 'this is where it errors With fldr .Title = "Select a Folder in which to save the output file" .AllowMultiSelect = False .InitialFileName = strPath If .Show -1 Then GoTo NextCode sItem = .SelectedItems(1) End With NextCode: GetFolder = sItem Set fldr = Nothing End Function |
#2
|
|||
|
|||
![]()
Question 1 solved- Found a way to do it here
(http://www.vbforums.com/archive/index.php/t-400121.html) for the benefit of future searchers. I'll try to get access to a 2007 machine to test the new code, and I'll create a new thread if I run into issues. Thank you, Keith "ker_01" wrote: Full code appended below. My goal is that this code (when triggered) will allow the user to select a destination folder and enter a filename, and select a source outlook folder. The code should then scrape each email in that folder to get the sent date/time, the subject line, and the sender, and dump that info into a flat file (which will be used in Excel). (1) Apparently outlook doesn't have an application.filedialogue (code errors out in the function on this line). What is the best way to allow a user to select a destination folder for a generated file? Alternatively, is there a way to determine the path to the desktop and always save to the desktop, given that each user's path to the desktop will be unique? (2) I'll need my code to work in both Outlook 2003 and 2007. I don't have direct access to a 2007 box, but would welcome feedback if you see anything in this code that is likely to fail in 2007 Thank you! Keith Sub ParseAlertEmails() '(strSource As String, strLabel As String) Set myOlApp = CreateObject("Outlook.Application") Set olns = myOlApp.GetNamespace("MAPI") Set myinbox = olns.PickFolder Set myItems = myinbox.Items Dim fso, tf Set fso = CreateObject("Scripting.FileSystemObject") UseFolder = GetFolder UseDateApp = Format(Now(), "YYMMDDHHmmss") UseFN = InputBox("Please enter the name of the destination file", "Save As") Set tf = fso.CreateTextFile(UseFN & " " & UseDateApp, True) StartCount = 0 strEmailContents = "" For Each outlookmessage In myinbox.Items If IgnoreEmail = False Then strEmailContents = outlookmessage.ReceivedTime strEmailContents = strEmailContents & ";" & outlookmessage.sender strEmailContents = strEmailContents & ";" & outlookmessage.Subject tf.Write strEmailContents & vbCrLf End If strEmailContents = "" StartCount = StartCount + 1 Next tf.Close Set fso = Nothing Set myOlApp = Nothing Set olns = Nothing Set myinbox = Nothing Set myItems = Nothing End Sub Private Function GetFolder(Optional strPath As String) As String Dim fldr As FileDialog Dim sItem As String Set fldr = Application.FileDialog(msoFileDialogFolderPicker) 'this is where it errors With fldr .Title = "Select a Folder in which to save the output file" .AllowMultiSelect = False .InitialFileName = strPath If .Show -1 Then GoTo NextCode sItem = .SelectedItems(1) End With NextCode: GetFolder = sItem Set fldr = Nothing End Function |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Outlook com add in questions | John | Add-ins for Outlook | 7 | October 25th 07 07:59 PM |
Outlook questions | Fredfarkwater | Outlook - Installation | 1 | February 14th 07 07:49 PM |
Need help scraping calendar info | rut | Outlook and VBA | 3 | July 7th 06 06:18 PM |
Some Questions about Outlook | Dotku | Outlook - General Queries | 4 | May 8th 06 03:00 PM |
Outlook Questions | ezstepper | Outlook - Calandaring | 0 | January 20th 06 07:21 PM |