vba passing list of variable - vba

I have already created a macro that creates individual files for me. Now having those files I have created another VBA job in outlook that will add the contact information to the e-mail, locate the needed file, and attach it to an e-mail. I need to do this to a list of about 50 different companies that I send these audits to. Currently I need to add a certain parameter to select what company I am using "V003" for example after this job is ran I go to the next one "V004" and so on.
I am looking for a way to provide VBA the list of 50 companies codes into which I have all as folders in a certain directory path. So when i kick off the job it will reference the folder named V003 in the directory path and use that as the VendorID variable I have created then loop back to the beginning and grab the next folder name V004 in the directory path and filter though until it gets to the last one.
Unless someone else has an idea that won't make me kick of the VBA job 50 times and pass in each variable. (Currently that's what I've been doing since I created these jobs and it's still a bit time consuming)
Dim GlobalVarEmail As String
Dim GlobalVarVendorName As String
Dim GlobalVendorId As String
Dim GlobalMonth As String
Dim GlobalYear As String
Dim GlobalAuditDate As String
Sub SendFilesbyEmail()
'the calling method of all sub methods.
GlobalVendorId = InputBox("What Vendor Letter are you trying to send out? (V Code: ex - V012)", "Vendor Code", "Type Here", 7500, 5000)
GlobalMonth = InputBox("What Month are you auditing for?(ex - Jan. Feb. Mar.)", "Month", "Type Here", 7500, 5000)
GlobalYear = InputBox("What year are you auditing for?(ex - 2016)", "Quarter", "Type Here", 7500, 5000)
GlobalAuditDate = InputBox("What is the audit date?(ex - 20160930)", "Quarter", "Type Here", 7500, 5000)
Call openExcel(GlobalVendorId)
Call SendAuditReport
End Sub
Public Function openExcel(UserReponse) As String
'this function is used to retrieve the vendor contact e-mail
Dim xlApp As Object
Dim sourceWB As Workbook
Dim sourceWS As Worksheet
Set xlApp = CreateObject("Excel.Application")
With xlApp
.Visible = False
.EnableEvents = True
End With
strFile = "G:\403(b)\User Folders\Chris W\SPARK Info\Contacts.xlsx"
Set sourceWB = Workbooks.Open(strFile, , False, , , , , , , True)
Set sourceWH = sourceWB.Worksheets("SPARK")
sourceWB.Activate
Rows("1:1").Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:$H$100").AutoFilter Field:=1, Criteria1:=UserReponse
Range("F1").Select
GlobalVarEmail = Selection.End(xlDown).Value
Range("B1").Select
GlobalVarVendorName = Selection.End(xlDown).Value
ActiveWorkbook.Close SaveChanges:=False
End Function
Function SendAuditReport()
'this function will create a e-mail, (subjectline & body), attach the needed audit letter, and insert the needed vendor contact e-mail.
Dim Fname As String
Dim sAttName As String
Dim olApp As Outlook.Application
Dim olMsg As Outlook.MailItem
Dim olAtt As Outlook.Attachments
Set olApp = Outlook.Application
Set olMsg = olApp.CreateItem(0) ' email
Set olAtt = olMsg.Attachments
' send message
With olMsg
.Subject = GlobalVarVendorName & " " & GlobalMonth & " " & GlobalYear & " SPARK Audit"
.To = GlobalVarEmail
.CC = "SPARK#AXA.com"
.Attachments.Add "G:\403(b)\User Folders\Chris W\Spark Audit\" & GlobalAuditDate & "\00-Ran Reports\" & GlobalVendorId & "\SPARK Audit Report " & GlobalVarVendorName & ".xlsx"
'you can add attachments here just type .Attachments.Add "folder path"
.HTMLBody = "Hello, <br /><br /> Attached is the file
'.Send
.Display
End With
End Function

You can enumerate folder names as such:
Dim objFSO As Object
Dim objFolder As Object
Dim objSubFolder As Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\pathtoyourparentfolder")
For Each objSubFolder In objFolder.subfolders
MsgBox objSubFolder.Name
Next objSubFolder
objSubFolder.Name will be the name of the folder and you can just pass this to GlobalVendorID.

Related

Server based rule to collate 500+ adresses into ~150 inbox folders

I have a Company Project where ~500 clients send Emails to the my project inbox. Those clients correspond to ~150 offices (I have an Excel-List of the email addresses & according offices).
Each office shall have one Outlook folder, so I can quickly check upon the past correspondence with a specific office.
The Project inbox is looked after and used by several co-workers, hence server- and not client based rules.
How do I set this up?
My simple idea in form of a pseudo code:
for each arriving email
if (from-adress is in "email & office-List")
move that email to outlook folder "according office name"
end if
end for
and the same for outgoing emails:
for each sent email
if (to-adress is in "email & office-List")
move that email to outlook folder "according office name"
end if
end for
Thanks for suggestions!
...and besides, can outlook folders be created programmatically from a list of names?
My solution is a skript i run daily on a manual basis since my employer doesnt allow scripts on arriving messages.
the logic in short is:
fetch list of emails & their corresponding offices (both string lists)
set up folder variables
loop through messages, and move them eventually
the code looks like
Option Compare Text ' makes string comparisons case insensitive
Sub sortEmails()
'sorts the emails into folders
Dim msg As Outlook.MailItem
Dim itm As Object
Dim adress As String
Dim pa As Outlook.PropertyAccessor
Const PR_SMTP_ADDRESS As String = _
"http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
'1) fetch emails
GetEMailsFolders locIDs, emails, n
'1.5) fetch folder objects
'Create an instance of Outlook & inbox reference
Dim Inbox As Outlook.MAPIFolder
Dim outbox As Outlook.MAPIFolder
Set outlookApp = New Outlook.Application
Set NS = outlookApp.GetNamespace("MAPI")
Set objOwner = NS.CreateRecipient("email#host.com")
objOwner.Resolve
'Set inbox = NS.GetSharedDefaultFolder(objOwner, olFolderInbox)
Set Inbox = NS.Folders("email#host.com").Folders("Inbox")
Set outbox = NS.Folders("email#host.com").Folders("Sent Items")
Dim basefolder As Outlook.MAPIFolder
Dim bfName As String
bfName = "Offices" 'name of the folder for the offices
Set basefolder = MkDirConditional(Inbox.Folders("Project folder"), bfName)
'2)loop through inbox & outbox emails
Dim destination As Outlook.MAPIFolder
Dim fold(1 To 2) As Outlook.MAPIFolder
Set fold(1) = Inbox
Set fold(2) = outbox
Dim LocID As String
For Each fol In fold 'loop through inbox & outbox
Debug.Print fol
'reverse fo loop because otherwise moved messages modify indices of following messages
For i = fol.Items.Count To 1 Step -1 'Each itm In fol.Items
Set itm = fol.Items(i)
If TypeName(itm) = "MailItem" Then ' others are AppointmentItem, MeetingItem, or TaskItem
Set msg = itm
'Debug.Print " " & msg.Subject
If fol = Inbox Then
' there are two formats of email adrersses.
If msg.SenderEmailType = "EX" Then 'check two kinds of email adress formats
adress = msg.Sender.GetExchangeUser().PrimarySmtpAddress
ElseIf msg.SenderEmailType = "SMTP" Then 'SMTP case
adress = msg.SenderEmailAddress
Else
Debug.Print " neither EX nor SMTP" & msg.Subject;
End If
pos = Findstring(adress, emails) ' position in the email / standort list
ElseIf fol = outbox Then
For Each rec In msg.Recipients
Set pa = rec.PropertyAccessor
adress = pa.GetProperty(PR_SMTP_ADDRESS)
pos = Findstring(adress, emails)
If pos > 0 Then
Exit For
End If
Next rec
End If
'4.5) if folder doesnt exist, create it
'5) move message
If pos > 0 Then
'Debug.Print " Its a Match!!"
LocID = locIDs(pos)
Set destination = MkDirConditional(basefolder, LocID)
Debug.Print " " & Left(msg.Subject, 20), adress, pos, destination
msg.Move destination
Else
'Debug.Print " not found!"
End If
Else
'Debug.Print " " & "non-mailitem", itm.Subject
End If
Next i
Next fol
End Sub
'// Function - Check folder Exist
Private Function FolderExists(Inbox As Outlook.MAPIFolder, FolderName As String) As Boolean
Dim Sub_Folder As MAPIFolder
On Error GoTo Exit_Err
Set Sub_Folder = Inbox.Folders(FolderName)
FolderExists = True
Exit Function
Exit_Err:
FolderExists = False
End Function
Function MkDirConditional(basefolder As Outlook.MAPIFolder, newfolder As String) As Outlook.MAPIFolder
Debug.Print newfolder & " ";
If FolderExists(basefolder, newfolder) Then
'folder exists, so just skip
Set MkDirConditional = basefolder.Folders(newfolder)
Debug.Print "exists already"
Else
'folder doesnt exist, make it
Set MkDirConditional = basefolder.Folders.Add(newfolder)
Debug.Print "created"
End If
End Function
'function to compare two strings, min the option compare text at the top line
Function Findstring(str As String, arr As Variant) As Integer
'returns -1 if a string is not found, otherwise its index
Findstring = -1
Dim i As Integer
i = 1
For Each Item In arr
'Debug.Print Item
If str = Item Then
Findstring = i
Exit For
End If
i = i + 1
Next
End Function
' function to fetch the lists of emails and offices
Sub GetEMailsFolders(ByRef rng1 As Variant, ByRef rng2 As Variant, ByRef n As Variant)
'declare variables
Dim xExcelFile As String
Dim xExcelApp As Excel.Application
Dim xWb As Excel.Workbook
Dim xWs As Excel.Worksheet
Dim xExcelRange As Excel.Range
Dim TotalRows As Long
'declare SPOC xls file
xExcelFile = "adresses.xlsx"
'open the file
Set xExcelApp = CreateObject("Excel.Application")
Set xWb = xExcelApp.Workbooks.Open(xExcelFile)
Set xWs = xWb.Sheets(1)
'extract LocIDs (column A), emails (column O) and thir number
n = xWs.Range(xWs.Range("A2"), xWs.Range("A2").End(xlDown)).Count ' works
ReDim rng1(1 To n) As Variant
ReDim rng2(1 To n) As Variant
For i = 1 To n
rng1(i) = xWs.Cells(i + 1, 1)
rng2(i) = xWs.Cells(i + 1, 15)
'Debug.Print rng1(i), rng2(i)
Next
Debug.Print "done reading LocIDs & emails"
End Sub

Want to Email a Certain Details while also attaching images from a certain Directory

I am creating a workbook where i want to create a Email Button. Which not only mail the contents of the workbook but also attach a certain directory to the Email as Attachments.
The directory is automatically created by a batch file with the following Coding.
mkdir %date:~-4,4%"-"%date:~-10,2%"-"%date:~-7,2%
This Create Folders with the name of current Date.
This is How the Folder Structure Looks like when it is created.
I researched a lot and created a code to send my context of the EXCEL File directly through a click of a button. But was not able to make code work for attachments as well.
The Following Code is used to Send my Mail.
Sub EmailRange()
Dim WorkRng As Range
On Error Resume Next
xTitleId = "Excalibur Mail"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Application.ScreenUpdating = False
WorkRng.Select
ActiveWorkbook.EnvelopeVisible = True
With ActiveSheet.MailEnvelope
.Introduction = "This is an automated Email. Please do not respond"
.Item.To = "" 'Senders Email ID
.Item.Subject = "Daily Counts"
.Item.Send
End With
Application.ScreenUpdating = True
End Sub
The Code Works fine and ask me for Range Selection and does send email to that specific Client. What i need now is to be able to attach all the images that are in the folder which displays the Current Date.
For Eg. if todays date is 26/03/2018. It will Create a folder named 2018-03-26. I need some help in sending my content as well as all the images that are in the current date folder.
I created a "aaa.txt" & "bbb.txt" in the new folder for testing. You can check this link on how to add all items in a file as attachment: https://www.experts-exchange.com/questions/27319804/Excel-VBA-Attach-All-Files-in-a-Directory.html
Option Explicit
Sub test()
Dim tdy As String
tdy = Format(Date, "yyyy-mm-dd")
Dim filePath As String
filePath = "YouPath\" & tdy & "\"
Dim strFileName As String
strFileName = Dir(filePath & "*.*")
ActiveWorkbook.EnvelopeVisible = True
With ActiveSheet.MailEnvelope
.Introduction = "This is an automated Email. Please do not respond"
.Item.To = "" 'Any mail Id You need
.Item.Subject = "Daily Counts"
.Item.Display
If FolderExists(filePath) Then
Do While Len(strFileName) > 0
.Item.attachments.Add filePath & strFileName
strFileName = Dir
Loop
Else
MsgBox "Folder " & tdy & " not Found!"
End If
End With
End Sub
Function FolderExists(ByVal path As String) As Boolean
FolderExists = False
Dim objFSO As Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(path) Then FolderExists = True
End Function

Write value to text file, not name of object

I have some code which works great if putting the values into an Excel sheet but when I have tried to make it write to a text file it just writes the following over and over again:
objAddressEntry.Name
objAddressEntry.Name
Code below. I've left in the bit that originally wrote to Excel but it's commented out.
Sub GetOutlookAddressBook()
' Need to add reference to Outlook
'(In VBA editor Tools References MS Outlook #.# Library)
' Adds addresses to existing Sheet called Address and
' defines name Addresses containing this list
' For use with data Validation ListBox (Source as =Addresses)
On Error GoTo error
Dim objOutlook As Outlook.Application
Dim objAddressList As Outlook.AddressList
Dim objAddressEntry As Outlook.AddressEntry
Dim intCounter As Integer
Application.ScreenUpdating = False
' Setup connection to Outlook application
Set objOutlook = CreateObject("Outlook.Application")
Set objAddressList = objOutlook.Session.AddressLists("Global Address List")
Application.EnableEvents = False
' Clear existing list
' Sheets("Address").Range("A:A").Clear
' Create text file
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim oFile As Object
Set oFile = fso.CreateTextFile("C:\Users\username\Desktop\test.txt")
'Step through each contact and list each that has an email address
For Each objAddressEntry In objAddressList.AddressEntries
If objAddressEntry.Address <> "" Then
intCounter = intCounter + 1
Application.StatusBar = "Address no. " & intCounter & " ... " & objAddressEntry.Address
' Write to text file
oFile.WriteLine "objAddressEntry.Name" & vbNewLine
' Sheets("Address").Cells(intCounter, 1) = objAddressEntry.Name
DoEvents
End If
Next objAddressEntry
' Close the text file
oFile.Close
Set fso = Nothing
Set oFile = Nothing
' Define range called "Addresses" to the list of emails
' Sheets("Address").Cells(1, 1).Resize(intCounter, 1).Name = "Addresses"
error:
Set objOutlook = Nothing
Application.StatusBar = False
Application.EnableEvents = False
End Sub
Note that I rarely use VBA so I apologise if this is a trivial issue. I have struggled to find anything relevant in previous questions/answers as the search terms are quite broad.
My question is: How do I make it write the actual value rather than the name of the object?
If you just want to write the .Name then,
oFile.WriteLine objAddressEntry.Name & vbNewLine
... but if you want to write the .Name in quotes then,
oFile.WriteLine chr(34) & objAddressEntry.Name & chr(34) & vbNewLine

Please close Excel application - Excel is open

I am not a VB person but I am asked to troubleshoot this issue. We have an Access database that is exporting two Access reports to an Excel workbook. It has been working for years. Recently we are getting an error message that the Excel application is open and must be closed. Both the database and Access template are on a network share drive. From what I can see we are not getting past this point. The server does not show Excel as being opened at the time of the error. I thank you in advance for your assistance.
Here is my code:
Private Sub ExportCounts_Excel()
Dim excelname As String
Dim AppExcel As New Excel.Application
Dim Wkb As Workbook
Dim Wksh As Worksheet
Dim Wksh1 As Worksheet
Dim Wksh2 As Worksheet
Dim obj As AccessObject
Dim dbs As Object
Dim rs As Object
Dim rstable As Object
Dim tempTable As String
Dim data As String
Dim Agent As String
Dim Name As String
Dim newfile As String
Dim tic As String
Dim lastrow As Long
Dim count As Integer
Dim recount As Integer
On Error GoTo Errorcatch
DoCmd.SetWarnings False
'*****************************************************************************
Dim fso As Object
Set fso = VBA.CreateObject("Scripting.FileSystemObject")
Call fso.CopyFile("\\cfbf-sql\mbdb\Counts Reports Template.xlsm", "\\cfbf-sql\itdb\IT-Test DBs\counts\Counts Reports.xls")
'see if the excel app is running
Dim MyXL As Object 'Variable to hold reference
Dim ExcelWasNotRunning As Boolean 'Flag for final release
On Error Resume Next
Set MyXL = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
ExcelWasNotRunning = True
End If
'Check if the Excel Application is running
If ExcelWasNotRunning = True Then
'If Excel is running then.............
MsgBox "Please Close your Excel Application" & vbCrLf _
& "and save your files before attempting" & vbCrLf _
& "to run the report", vbInformation, _
"Microsoft Excel is open"
Set MyXL = Nothing
Exit Sub
Else 'Excel is not running
'Optional - to storage the file name entered by user
Dim Message, Title, Default, MyValue
Message = "Enter a name for the file" ' Set prompt.
Title = "Assign File Name" ' Set title.
'Format date to use it as file name and report title
Dim varMonthNum As Variant
Dim varDayNum As Variant
Dim varYear As Variant
Dim varFileDate As Variant
'Get the month, day, and year from LastFriday text box
varMonthNum = Month(LastFriday.Value)
varDayNum = Day(LastFriday.Value)
varYear = Year(LastFriday.Value)
'Format the date to assign it as part of the file name
varFileDate = varMonthNum & "-" & varDayNum & "-" & varYear
'use the following variable to format the file name
Default = Me.CurrentYear.Value & " CFBF Membership Report as of " & varFileDate ' Set default.
' Display message, title, and default value.
MyValue = InputBox(Message, Title, Default)
If StrPtr(MyValue) = 0 Then 'IF the vbCancel Button is selected by the user
'Exit the procedure
Exit Sub
Else 'Create the excel report
'*****************************************************************************
'excelname = "\\member2\MBDB\Counts Reports Template.xls"
excelname = "\\cfbf-sql\MBDB\Counts Reports Template.xls"
'For the new fiscal year 2014
'newfile = "\\web3\FBMNData\WEEKLY COUNTY REPORTS 2011\" & MyValue & ".xls"
'newfile = "\\web3\FBMNData\WEEKLY COUNTY REPORTS 2013\" & MyValue & ".xls"
'newfile = "\\web3\FBMNData\WEEKLY COUNTY REPORTS 2014\" & MyValue & ".xls"
'newfile = "\\web3\FBMNData\WEEKLY COUNTY REPORTS 2015\" & MyValue & ".xls"
'==============================================================================
'**** Comments by: Armando Carrasco - 11/21/2014 ***
'**** MMR - Kate Tscharner - requested to stop posting excel file in ***
'**** the counties FTP site and to place the file in the everyone folder ***
'**** MMR also requested to move all "WEEKLY COUNTY REPORTS YYYY" folders ***
'**** from WEB3 to "\\cfbf-fp\Everyone\MembershipReports\" ***
'newfile = "\\cfbf-fp\Everyone\MembershipReports\WEEKLY COUNTY REPORTS 2015\" & MyValue & ".xls"
'==============================================================================
'**** Comments by: Armando Carrasco - 01/21/2014 ***
'**** MMR - Kate Tscharner - WO 1284 - Comments ***
'**** We have had the request from several county Farm Bureaus to restore ***
'**** Placing the old network directory location in WEB3. ***
newfile = "\\cfbf-reports\FBMNData\WEEKLY COUNTY REPORTS 2017\" & MyValue & ".xls"
'==============================================================================
I'd suggest re-organizing a bit:
Dim MyXL As Object 'Variable to hold reference
Dim ExcelWasRunning As Boolean 'Flag for final release
On Error Resume Next '<< ignore error if Excel not running
Set MyXL = GetObject(, "Excel.Application")
On Error Goto 0 '<< cancel the On Error Resume Next so you
' don't miss later (unexpected) issues
ExcelWasRunning = Not MyXL Is Nothing '<< If Excel was running then MyXL
' is set to the Excel instance
If ExcelWasRunning Then
MsgBox "Please Close your Excel Application" & vbCrLf _
& "and save your files before attempting" & vbCrLf _
& "to run the report", vbInformation, _
"Microsoft Excel is open"
Set MyXL = Nothing
Exit Sub '<< Shouldn't really need this, since the rest of your code
' is in the Else block...
Else
'Excel is not running
'Rest of your code here
End If

VBA retrieve HTMLBody from Outlook mail

First I create an email via Outlook:
Sub CreateHTMLMail()
'Creates a new e-mail item and modifies its properties.
Dim olApp As Outlook.Application
Dim objMail As Outlook.MailItem
Set olApp = Outlook.Application
'Create e-mail item
Set objMail = olApp.CreateItem(olMailItem)
Dim sHTML_Open As String
Dim sHTML_Introduction As String
Dim sHTML_Goodbye As String
Dim sHTML_Close As String
Dim sHTML_Process_Date As String
Dim sHTML_Processor As String
Dim sHTML_Issuer As String
Dim sHTML_Details As String
Dim sHTML_Body As String
sHTML_Open = "<HTML><BODY>"
sHTML_Introduction = "Hi team,<BR/><BR/>" & _
"Data is ready to process. Please find details as below.<BR/>"
sHTML_Process_Date = "<P ID='PROCESSDATE'>28 February 2013</P>"
sHTML_Processor = "<P ID='PROCESSOR'>AKSHAY</ID></P>"
sHTML_Issuer = "<P ID='ISSUER'>DATAGROUP.COM</ID></P>"
sHTML_Details = "<P ID='DETAILS'>" & _
"<UL>" & _
"<LI>Fimta23456 09:00:00 flor345</LI>" & _
"<LI>Fimta23456 09:00:00 flor345</LI>" & _
"</UL>" & _
"</P><BR/>"
sHTML_Goodbye = "Thanks"
sHTML_Close = "</BODY></HTML>"
sHTML_Body = sHTML_Open & sHTML_Introduction & sHTML_Process_Date & sHTML_Processor & sHTML_Issuer & _
sHTML_Details & sHTML_Goodbye & sHTML_Close
With objMail
'Set body format to HTML
.BodyFormat = olFormatHTML
.To = "Kim Gysen"
.Subject = "data remit file"
.HTMLBody = sHTML_Body
.Display
End With
End Sub
Via code, I want to retrieve values based on ID.
This seemed the cleanest way for me, I don't particulary like the "split" method because it's kind of hard coding; not very dynamic and kinda unreliable.
Unfortunately when I retrieve the HTML body, I cannot retrieve the original HTML, as it is distorted by Outlook:
Sub Get_OL()
Dim oFolder As MAPIFolder
Dim oItem As Variant
Dim sHTML_Body As String
Dim sHTML_Process_Date As String
Dim sHTML_Processor As String
Dim sHTML_Issuer As String
Dim sHTML_Details As String
Dim oExcel As Object
Dim oBook As Workbook
Set oExcel = CreateObject("Excel.Application")
Set oBook = oExcel.Workbooks.Add
'Access the outlook inbox folder
Set oFolder = GetNamespace("MAPI").PickFolder
'On error resume next usually not to use, but feteching emails may give unexpected errors
On Error Resume Next
For Each oItem In oFolder.Items
If TypeOf oItem Is Outlook.MailItem Then
If oItem.Subject Like "*data remit file*" Then
'Turn off on error resume next asap
On Error GoTo 0
sHTML_Body = oItem.HTMLBody
Debug.Print sHTML_Body
Exit For
End If
End If
Next oItem
End Sub
On debug.print, this is what I get (only putting the last line of the Format):
</o:shapelayout></xml><![endif]--></head><body lang=EN-GB link=blue vlink=purple><div class=WordSection1><p class=MsoNormal>Hi team,<br><br>Data is ready to process. Please find details as below.<br><br><o:p></o:p></p><p>28 February 2013<o:p></o:p></p><p id=PROCESSOR>AKSHAY<o:p></o:p></p><p id=ISSUER>DATAGROUP.COM<o:p></o:p></p><ul type=disc><li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;mso-list:l0 level1 lfo1'>Fimta23456 09:00:00 flor345<o:p></o:p></li><li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;mso-list:l0 level1 lfo1'>Fimta23456 09:00:00 flor345<o:p></o:p></li></ul><p class=MsoNormal><br>Thanks<o:p></o:p></p></div></body></html>
I would like to retrieve the original HTML that I put in the HTMLBody.
2 ways:
1) parsing text - several things to do (not recommended: hard-coding)
All what you need is to parse text, but MSDN shows how to do it using InStr function. I would strongly suggest to use RegEx to parse html text. Note: reference to MS VBScript Regular Expressions x.x is needed.
Simple Regular Expression Tutorial for Excel VBA
2) using UserProperites of MailItem object (recommended)
If MailItem doesn't contains your propert(y)ies, than there is nothing to do ;)
How to: Add custom property