Hi,
Part of a program i am doing will be sending emails in a mail merge type fashion with the data stored in Excel.
I have the code for sending the email in HTML format all OK but i cant get my head around where to start with looping through an excel file (have it opening).
In each row;
Column A to set vrbCallRef
Column B to set vrbUserName
Column C to set vrbEmail
Column D to set vrbProblem
Column E to set vrbResolution
As i mentioned i have the code to send the email so i just need it to set them, run my "SEND THE EMAIL" code and then move onto the next row and do it all again until there is no other data in the rows.
Here is my code so far but it does not yet contain anything apart from opening the excel book in regards to the loop:
if anyone could poitn me in the right direction or show me how the loop works properly i would really appreciate it.
Many Thanks
Paul
Part of a program i am doing will be sending emails in a mail merge type fashion with the data stored in Excel.
I have the code for sending the email in HTML format all OK but i cant get my head around where to start with looping through an excel file (have it opening).
In each row;
Column A to set vrbCallRef
Column B to set vrbUserName
Column C to set vrbEmail
Column D to set vrbProblem
Column E to set vrbResolution
As i mentioned i have the code to send the email so i just need it to set them, run my "SEND THE EMAIL" code and then move onto the next row and do it all again until there is no other data in the rows.
Here is my code so far but it does not yet contain anything apart from opening the excel book in regards to the loop:
Code:
Private Sub btnSMails_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSMails.Click
Dim vrbMailCount
Dim vrbCallRef
Dim vrbUserName
Dim vrbEmail
Dim vrbProblem
Dim vrbResolution
Dim vrbSignature
Dim oExcel As New Microsoft.Office.Interop.Excel.Application
Dim oBook As Microsoft.Office.Interop.Excel.Workbook
Dim oSheet As Microsoft.Office.Interop.Excel.Worksheet
Dim oApp = New Outlook.Application
Dim oAppt As MailItem = oApp.CreateItem(OlItemType.olMailItem)
'#### SELECT WORKBOOK ####
oBook = oExcel.Workbooks.Open("U:\Coding\Closures2\Closures\Referencing Files\Output.xlsx")
oSheet = oBook.Worksheets(1)
'############# TEMP VARIABLE SETTINGS TO CHECK EMAIL FORMAT ###############
'vrbCallRef = "HF123456"
'vrbMailCount = "5"
'vrbUserName = "Paul"
'vrbEmail = "paul.oconnor@phoenix.co.uk"
'vrbProblem = "Virus on HE00086"
'vrbResolution = "Scanned device, Virus Removed"
vrbSignature = "Paul O'Connor"
'#### SEND THE EMAIL ####
oAppt.To = vrbEmail
oAppt.Subject = "Call Closure Request" & " " & vrbMailCount & ". Reference:" & " " & vrbCallRef
oAppt.BodyFormat = OlBodyFormat.olFormatHTML
oAppt.HTMLBody = "Hi" & " " & vrbUserName & ",<br><br>" _
& "We have been advised by the onsite engineer that the following issue logged under<b>" & " " & vrbCallRef & " " & "</b>has been resolved." _
& "<br><br>" _
& "<b>Problem Description:</b><br>" _
& vrbProblem & "<br><br>" _
& "<b>Resolution:</b><br>" _
& vrbResolution & "<br><br>" _
& "Please could you confirm by replying to this email if you are happy for us to close this call?<br><br>" _
& "Many Thanks<br>" _
& vrbSignature
oAppt.Send()
oApp = Nothing
oAppt = Nothing
End SubMany Thanks
Paul