Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old January 31st, 2005, 10:59 AM
wdale wdale is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 26 wdale User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 55 sec
Reputation Power: 0
Import Macro

Hi,

I am trying to create an email survey, the survey data returned is in the form of an outlook attachment postdata.att.

What I would like to do is search the email inbox for emails containing these attachments and then take the data from the attachment and import it into an excel spreadsheet. I managed to find the following code:

Public Sub ReadEmails()
' remember to include a reference to Outlook library

Dim olApp As Outlook.Application
Dim olNamespace As Outlook.Namespace
Dim olFolder As Outlook.MAPIFolder
Dim olMail As Outlook.MailItem
Dim lngRow As Long
Dim intAtt As Integer
Dim wbkTemp As Workbook
Dim strTempFile As String

Set olApp = New Outlook.Application
Set olNamespace = olApp.GetNamespace("MAPI")
Set olFolder = olNamespace.GetDefaultFolder(olFolderInbox)

lngRow = 1
' go thru all mail in Inbox
For Each olMail In olFolder.Items
' only check those with attachments
For intAtt = 1 To olMail.Attachments.Count
' only those with xls files
If InStr(1, olMail.Attachments(intAtt).Filename, ".xls", vbTextCompare) > 0 Then
' get folder and filename for att file
strTempFile = ThisWorkbook.Path & Application.PathSeparator & olMail.Attachments(intAtt).Filename
' save it so we can open and read it
olMail.Attachments(intAtt).SaveAsFile strTempFile
Set wbkTemp = Workbooks.Open(strTempFile)
With ThisWorkbook.ActiveSheet
.Cells(lngRow, 1) = olMail.Attachments(intAtt).Filename
.Cells(lngRow, 2) = wbkTemp.Sheets(1).Range("A1")
End With
lngRow = lngRow + 1
' close and destroy temporary excel file
wbkTemp.Close False
Set wbkTemp = Nothing
Kill strTempFile
End If
Next
Next

Set olMail = Nothing
Set olFolder = Nothing
Set olNamespace = Nothing
Set olApp = Nothing
End Sub



Obviously this is for xls attachments but mine is a .att attachment which would simply include data like
moreinfo=yes
rating=good


i can import the data manually in excel using the following macro:

ActiveWorkbook.Worksheets.Add
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Documents\POSTDATA.ATT" _
, Destination:=Range("A1"))
.Name = "POSTDATA"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = "="
.TextFileColumnDataTypes = Array(2, 2)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With

but how do I combine these 2 into something which will take each email attachment in turn and import the data into excel, copying the certain details?

Thank you for all your help

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Import Macro


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT