Hi,
i have been putting together a program that will send multiple emails for work. we have a userlist on a excel file because a proper data base is out of question :-(.
i am now a bit stuck as to where to start with this next part.
in that datagrid view there will be 4 columns. i need to pull the name in the datagrid first column and cross reference it with the names stored in Column D of a worksheet. if the name matches then grab the email address from column E.
if i am thinking correctly this will need to be done at the point of email sending so i was thinking maybe a loop on the email but was not sure how to loop it in to:
1. pull name --->
2. pull email for name --->
3. pull other 3 columns details.
Would these need to be set to a variable? some have some very lengthy descriptions that will go in (2 of other 3 columns)
any help or point in the right direction would be much appreciated
Many Thanks
Paul
i have been putting together a program that will send multiple emails for work. we have a userlist on a excel file because a proper data base is out of question :-(.
i am now a bit stuck as to where to start with this next part.
Code:
Private Sub btnImport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImport.Click
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
'#### select workbook to get data from ####
oBook = oExcel.Workbooks.Open("C:\Documents and Settings\paul.oconnor\My Documents\IGNIS RAW DATA2.XLSX")
oSheet = oBook.Worksheets(1)
'#### delete the columns not required ####
Dim rg As Excel.Range = oSheet.Columns("A:AG")
rg.Select()
rg.Delete()
oBook.Save()
Dim rg2 As Excel.Range = oSheet.Columns("B:AN")
rg2.Select()
rg2.Delete()
oBook.Save()
Dim rg3 As Excel.Range = oSheet.Columns("C:CW")
rg3.Select()
rg3.Delete()
oBook.Save()
Dim rg4 As Excel.Range = oSheet.Columns("E:CB")
rg4.Select()
rg4.Delete()
oBook.Save()
Dim rg5 As Excel.Range = oSheet.Columns("A")
Dim rg6 As Excel.Range = oSheet.Columns("C")
rg5.Select()
rg5.Cut()
rg6.Insert()
oBook.Save()
oExcel.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(oBook)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel)
oBook = Nothing
oExcel = Nothing
'oBook = oExcel.Workbooks.Open("C:\Documents and Settings\paul.oconnor\My Documents\IGNIS RAW DATA2.XLSX")
'oSheet = oBook.Worksheets(1)
'#### get data and display in datagrid #####
Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim DtSet As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.ACE.OLEDB.12.0;Data Source='C:\Documents and Settings\paul.oconnor\My Documents\IGNIS RAW DATA2.XLSX';Extended Properties=Excel 12.0;")
MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [IGNIS RAW DATA2$]", MyConnection)
MyCommand.TableMappings.Add("Table", "Resolved Calls")
DtSet = New System.Data.DataSet
MyCommand.Fill(DtSet)
DataGridView1.DataSource = DtSet.Tables(0)
MyConnection.Close()
''#### get email address for user #####
'oBook = oExcel.Workbooks.Open("C:\Documents and Settings\paul.oconnor\My Documents\User list.xlsx")
'oSheet = oBook.Worksheets(1)
End Sub
'#### send the mails ####
Private Sub btnSMails_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSMails.Click
Dim objApp As Object
Dim objEmail As Object
objApp = CreateObject("Outlook.Application")
objEmail = objApp.CreateItem(0)
With objEmail
.To = "someone@somecompnay.co.uk"
.Subject = "Closure Reqeust For Call: "
.bodyformat = Outlook.OlBodyFormat.olFormatHTML
.HTMLBody = "<html> <head><title>Testing</title></head><body><table rules=""none"" border=""1"" frame=""box""><tr>" & _
" <td><Label id=""verify"">Test Text:</Label></td><td width=""233"">" & _
"<INPUT id=""passedText"" type=""text"" maxLength=""25"" size=""82"" ></td>" & _
"</tr></table></body></html>"
.display(True)
End With
objEmail = Nothing
objApp = Nothing
End Sub
if i am thinking correctly this will need to be done at the point of email sending so i was thinking maybe a loop on the email but was not sure how to loop it in to:
1. pull name --->
2. pull email for name --->
3. pull other 3 columns details.
Would these need to be set to a variable? some have some very lengthy descriptions that will go in (2 of other 3 columns)
any help or point in the right direction would be much appreciated
Many Thanks
Paul