Geting data from excel to outlook

Status
Not open for further replies.

densetax2

Member
Outlook version
Email Account
Exchange Server
Hi, I have data in excel.The script has for loop to compare the data inside the excel. what is best way to fetch it from outlook vba. i knew that opening a excel is slower. Snap shot of the excel is attached.
 

Attachments

  • 1.jpg
    1.jpg
    69.3 KB · Views: 475
That's for this https://forums.slipstick.com/thread...en-sent-specific-address-during-specfic-time/ correct?

I haven't had a chance to look at it - but you'll need to set the excel object, check the date and get the user name. I did a quick google and didn't find code samples that did anything like this - most we run from excel to send mail or create appt.

I found this - Read information from a closed workbook using VBA in Microsoft Excel - which shows how to read data from a closed workbook. Even if the book is open it will give you an idea of how to read it.

It's usually better to use an array and this shows how to read the sheet into an array - Reading worksheet values into arrays - JP Software Technologies - but whether an array is really better for this, I don't know.
 
Hi, can u suggest any improvement on the below code.

=======================================================================================

'this function returns email id to respective name. These emailid's are available in the outlook.

Function EmailAdd(nameid) As String
Select Case nameid
' add the name as it is in the excel
Case "Zakir"
nameid = "xxxxxx@xxxxxxxx"
Case "Joy"
nameid = "xxxxx@xxxx.com"
End Select
End Function

===================================================================================

'Main fucntion

Sub SendEmailToPlafrom()

Dim strPath As String

strPath = 'path of file

'myFileExists function calls the fucntion to check if the file exists

If myFileExists(strPath, True) Then

Dim xlApp As Object

Dim sourceWB As Workbook

Dim sourceWS As Worksheet

Set xlApp = CreateObject("Excel.Application")

Dim myDate As Date

'my date is the date format which is same as date in excel

myDate = Format(Date, "mm/dd/yyyy")

'set outlook

Set olApp = New Outlook.Application
Dim olNs As Outlook.NameSpace
Dim olMail As Outlook.MailItem
Set olNs = olApp.GetNamespace("MAPI")
Set olMail = olApp.CreateItem(olMailItem)

'opens and retrives the value from excel

Set sourceWB = Workbooks.Open(strPath)

Set sourceWH = sourceWB.Worksheets("Sheet1")

lastrow = Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

I = 3 'since the date starts from 3rd row
If myDate > Cells(lastrow, 2) Then 'check if mydate is greater that the date in excel
name1 = "False"
Else
Do Until I = lastrow
If Cells(I, 1) <= myDate And Cells(I, 2) >= myDate Then
If (myDate) >= (Cells(lastrow, 2) - 5) Then
Result5 = MsgBox("The IMo_Oncall is till" & Cells(lastrow, 2).Value & ",Do you want to sent mail to remainder to IMO", vbYesNo)
If Result5 = Yes Then
With olMail
.To = "xxxxx@gmail.com"
.Subject = "Kindly provide with the latest On_Call sheet"
End With
olMail.Display
End If
End If
searchstring = Cells(I, 3).Value
If InStr(searchstring, "|") > 0 Then
pos = InStr(1, searchstring, "|")
name1 = Trim(Mid(searchstring, 1, pos - 1))
name2 = Trim(Mid(searchstring, pos + 1))
strEmailTo1 = EmailAdd(name1)

strEmailTo2 = EmailAdd(name2) ' this function gives the emailid to that respective name. manualy entered.
Else
name1 = Trim(searchstring)
strEmailTo1 = EmailAdd(name1) ' this function gives the emailid to that respective name. manualy entered.
End If
End If
If pos <> 0 Then Exit Do
I = I + 1
Loop
End If
'Clean up
Set xlWS = Nothing
Set xlWB = Nothing
xlApp.Quit
Set xlApp = Nothing

End If
If name1 = False Then
With olMail
.To = "xxxxxxxx@gmail.com"
.CC = strEmailCC
.Subject = "Kindly provide with the latest On_Call sheet"
.Body = "Hi" & vbCrLf & "Kindly sent an updated On_Call sheet." & vbNewLine & "The last date available is" & " " & Cells(lastrow, 2) & vbNewLine

End With
olMail.Display

Else
strEmailCC = "xxxxx@rediffmail.com ; xxxxx@gmail.com"

olMail.To = name1
olMail.Body = "Good Morning, " & vbCrLf & olMail.Body
End If
olMail.Display

Exit Sub

End Sub
 
is it working? (I didn't test it yet) - it looks good just reading through it.
 
Yes, its working. i just want to know if any Fine tuning can b done. Like i use a function to resolve an emailid, ie;manual entry of emailid Fr each name in that function. Is there another way.
 
If the names are in your address book or gal, outlook should resolve them.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
J Outlook VBA to send from Non-default Account & Data Files Outlook VBA and Custom Forms 2
C Advanced search terms for "Outlook Data File" Using Outlook 1
C Populate form data into message body Outlook VBA and Custom Forms 1
CWM550 Saving Data: Don't check certain folders Using Outlook 2
CWM550 Importing " Old Skool" Data Using Outlook 0
W Create a Quick Step or VBA to SAVE AS PDF in G:|Data|Client File Outlook VBA and Custom Forms 1
Wotme create email only data file Using Outlook 1
V Backup Calendar, Contacts, Tasks in an POP3 data file Using Outlook 3
e_a_g_l_e_p_i Changing where data .pst is saved to Using Outlook 3
J Deliver new messages to New or Existing Data File? Using Outlook 2
G Outlook 2016: Want IMAP Data Files on My D: Drive and Not C: Drive Using Outlook 1
T vba extract data from msg file as attachment file of mail message Outlook VBA and Custom Forms 1
D Outlook 2016 Unable to load Outlook data pst file Using Outlook 5
V Form data not sending for some users Outlook VBA and Custom Forms 2
D Outlook VBA error extracting property data from GetRules collection Outlook VBA and Custom Forms 10
J Outlook 2013 Change color of text in data fields of contacts in Outlook 2013? Using Outlook 10
T How can Exchange be configured to sync/push one-way so that the server data can't be affected Exchange Server Administration 0
T Extract Data From Outlook Tasks Using Outlook 0
F outlook.com Exchane Server corrupts data Since September 2019 Using Outlook.com accounts in Outlook 6
T Extract Data From Outlook Tasks Using Outlook 0
E To convert imported data to custom fields in Task list Outlook VBA and Custom Forms 1
R "Can't store Outlook data files under the AppData folder. Please choose another folder." Using Outlook 6
C How to export Outlook data to csv? Using Outlook 0
RBLampert Assigning a newly (re)created e-mail account to a specific .pst data file Using Outlook 2
S newly added shared mailboxes downloading 500GB data a day Exchange Server Administration 1
M Using field names to capture a data element Using Outlook 0
S Custom Form, copy user field data to message body Outlook VBA and Custom Forms 12
M Outlook 2016 Requesting data from server Using Outlook 0
G Entered data in custom field goes in card and does not stay in list view Outlook VBA and Custom Forms 1
E Copying data from e-mail attachement to EXCEL file via macro Outlook VBA and Custom Forms 38
Sofia Manni Some of my favorite data in outlook. Using Outlook 2
A Outlook 2016 Will Not Show Any Data In the People Pane Using Outlook 17
A Script to fetch data from mails in restricted collection and sending them to excel Using Outlook 1
Commodore Search cannot complete the indexing of your Outlook data Using Outlook 6
P Microsoft Outlook is requesting data from the server Using Outlook 2
S BCM Auto Backup Data and Customizations BCM (Business Contact Manager) 6
K How to access emails found to be located in "Top of Outlook data file"? Using Outlook 3
M adding corresponding contact form data on a mass scale Using Outlook 5
J Calendar data can be viewed on Outlook.com, but no longer syncs to Outlook 2013 Using Outlook.com accounts in Outlook 3
M Retrieve data from GAL and put it in Clipboard Using Outlook 1
G How to Copy Multi Select Listbox Data to Appointment Outlook VBA and Custom Forms 3
G Using Data From Combo Box in Appointment Body Outlook VBA and Custom Forms 6
P How to copy and append data from Outlook 2016 message into Excel 2016 workbook Using Outlook 0
Diane Poremsky Set Another Data File as Default When Using an Exchange Account Using Outlook 0
Diane Poremsky How to Compact the Data File When you Close Outlook Using Outlook 0
T Uploading Outlook 2016 Contacts to Exchange Server Drops "Company" field data in 30% of records Exchange Server Administration 4
Diane Poremsky Rename Email Accounts and Data Files in the Folder List Using Outlook 0
J create .pst data file for new gmail account Using Outlook.com accounts in Outlook 1
M Dilemma: to add to existing data file or not to? Using Outlook 16
R Exporting Excel data to Outlook 2016 Calendar Outlook VBA and Custom Forms 20

Similar threads

Back
Top