LessThanDot Site Logo

LessThanDot

A Technical Community for IT Professionals

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Highly Rated Users

Forum
No Posts Rated

Top 50
Given
Received

Links

Wiki
Blog

Forum Statistics

Users
Members:
1882
Members Online:
2
Guests Online:
85

Total Post History
Posts:
81456
Topics:
18718

7-Day Post History
New Posts:
0
New Topics:
0
Active Topics:
0

Our newest member
justanails28

Other

FAQ
All times are UTC [ DST ]

Read file & create a new task by outlook vba

Please wait...

Read file & create a new task by outlook vba

Postby ZmrAbdulla on Wed Oct 21, 2009 6:00 am

I have never done any programing with outlook.

I want to read a file (text/ini/csv/xml) from outlook vba and add those details to a new task.

I have a simple exe located in the common server that is being used for maintenance & other service requests.
Not all the users have outlook.
The exe creates a file (now it is xml) of their requests. I want my program to read each one of them(on a specified interval) and add it to my outlook.

I am having vb.net exe that doing the job, takes a lot of memory. I thought it will be better to use something within outlook that is always open.
Zameer Abdulla
User avatar
ZmrAbdulla
LTD Senior Moderator
LTD Senior Moderator
LTD Bronze - Rating: 54LTD Bronze - Rating: 54
 
Posts: 225
Joined: Thu Oct 18, 2007 7:43 am
Location: United Arab Emirates
Unrated

Re: Read file & create a new task by outlook vba

Postby Remou on Fri Oct 23, 2009 8:16 pm

I am not sure where you are getting stuck, so here are a few notes.

  1. Sub ReadFile()
  2. Dim fs As Object
  3. Dim f As Object
  4. Dim a As Variant
  5.  
  6.     Set fs = CreateObject("Scripting.FileSystemObject")
  7.     Set f = fs.OpenTextFile("C:\Docs\Tasks.txt", 1) '1=for reading
  8.    
  9.     Do While f.AtEndOfStream = False
  10.         a = Split(f.ReadLine, "|")
  11.    
  12.         CreateTask a(0), a(1), a(2), Now
  13.     Loop
  14.    
  15. End Sub
  16.  
  17. Sub CreateTask(AssignToEmail, TaskSubject, TaskBody, TaskDateTime)
  18. Dim oTask As Outlook.TaskItem
  19. Dim AssignedTo As Outlook.Recipient
  20. Dim oNS As Outlook.NameSpace
  21.  
  22.        
  23.     Set oTask = CreateItem(olTaskItem)
  24.    
  25.     oTask.Assign
  26.     Set AssignedTo = oTask.Recipients.Add(AssignToEmail)
  27.     oTask.Subject = TaskSubject
  28.     oTask.Body = TaskBody
  29.     oTask.DueDate = TaskDateTime
  30.     oTask.Importance = 2 'olImportanceHigh
  31.     oTask.ReminderSet = True
  32.     'oTask.Save
  33.    
  34.     'Pick Display or Send
  35.     oTask.Display
  36.     'OutlookTask.Send
  37.    
  38.     'Clean up
  39.     Set oTask = Nothing
  40.  
  41. End Sub
Stop quoting laws to us. We carry swords.
User avatar
Remou
LTD Admin
LTD Admin
LTD Gold - Rating: 971LTD Gold - Rating: 971LTD Gold - Rating: 971LTD Gold - Rating: 971LTD Gold - Rating: 971
LTD Gold - Rating: 971LTD Gold - Rating: 971LTD Gold - Rating: 971LTD Gold - Rating: 971LTD Gold - Rating: 971
LTD Gold - Rating: 971
 
Posts: 5414
Joined: Sun Oct 14, 2007 11:26 am

Re: Read file & create a new task by outlook vba

Postby ZmrAbdulla on Sun Oct 25, 2009 5:52 am

Thanks Remou,
I am sure there is no timer in vba / userforms.
Do you suggest Sleep() for this purpose
  1. Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)


Or anything else out there?
I want this code to run for the first time open outlook & every hour from then until outlook is closed.
Zameer Abdulla
User avatar
ZmrAbdulla
LTD Senior Moderator
LTD Senior Moderator
LTD Bronze - Rating: 54LTD Bronze - Rating: 54
 
Posts: 225
Joined: Thu Oct 18, 2007 7:43 am
Location: United Arab Emirates
Unrated

Re: Read file & create a new task by outlook vba

Postby Emtucifor on Sun Oct 25, 2009 6:05 am

I don't know what the ramifications of Sleep are on performance, but be aware there's SleepEx and WaitForSingleObject, which may give you more options...
God cries a little bit every time someone builds a database.
User avatar
Emtucifor
Guru
Guru
LTD Gold - Rating: 1033LTD Gold - Rating: 1033LTD Gold - Rating: 1033LTD Gold - Rating: 1033LTD Gold - Rating: 1033
LTD Gold - Rating: 1033LTD Gold - Rating: 1033LTD Gold - Rating: 1033LTD Gold - Rating: 1033LTD Gold - Rating: 1033
LTD Gold - Rating: 1033
 
Posts: 2835
Joined: Fri May 30, 2008 9:30 pm
Location: Bellingham, WA
Unrated

Re: Read file & create a new task by outlook vba

Postby ZmrAbdulla on Sun Oct 25, 2009 9:06 am

I am actually not interested to use API calls. Looking for a simple solution to replace the timer control.
And I don't know how to use(if possible) those C++ code in VBA.
Zameer Abdulla
User avatar
ZmrAbdulla
LTD Senior Moderator
LTD Senior Moderator
LTD Bronze - Rating: 54LTD Bronze - Rating: 54
 
Posts: 225
Joined: Thu Oct 18, 2007 7:43 am
Location: United Arab Emirates
Unrated

Re: Read file & create a new task by outlook vba

Postby Remou on Sun Oct 25, 2009 9:50 am

I don't recall needing to "wait" in a real system, but for myself, I would generally use the system clock.

I have also seen:

  1. Set WshShell = WScript.CreateObject("WScript.Shell")
  2. WScript.Sleep(600000)
Stop quoting laws to us. We carry swords.
User avatar
Remou
LTD Admin
LTD Admin
LTD Gold - Rating: 971LTD Gold - Rating: 971LTD Gold - Rating: 971LTD Gold - Rating: 971LTD Gold - Rating: 971
LTD Gold - Rating: 971LTD Gold - Rating: 971LTD Gold - Rating: 971LTD Gold - Rating: 971LTD Gold - Rating: 971
LTD Gold - Rating: 971
 
Posts: 5414
Joined: Sun Oct 14, 2007 11:26 am
Unrated

Re: Read file & create a new task by outlook vba

Postby ZmrAbdulla on Sun Oct 25, 2009 12:03 pm

I think it will not work in VBA. It gives me an error of Object Required.
Zameer Abdulla
User avatar
ZmrAbdulla
LTD Senior Moderator
LTD Senior Moderator
LTD Bronze - Rating: 54LTD Bronze - Rating: 54
 
Posts: 225
Joined: Thu Oct 18, 2007 7:43 am
Location: United Arab Emirates
Unrated

Re: Read file & create a new task by outlook vba

Postby ZmrAbdulla on Sun Oct 25, 2009 12:06 pm

Zameer Abdulla
User avatar
ZmrAbdulla
LTD Senior Moderator
LTD Senior Moderator
LTD Bronze - Rating: 54LTD Bronze - Rating: 54
 
Posts: 225
Joined: Thu Oct 18, 2007 7:43 am
Location: United Arab Emirates
Unrated