Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming VBA / November 2006

Tip: Looking for answers? Try searching our database.

VBA Disapperas

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nick_NZ - 23 Nov 2006 23:41 GMT
Hi,

I have a VBA that turn emails into tasks in Outlook XP, and for some reason
it disappears causing the subsequent rule to fail. It usually runs around 10
times, then the code simply goes away!

I have no idea to why this is occurring, and any help would be greatly
appreciated.
Michael Bauer [MVP - Outlook] - 24 Nov 2006 06:18 GMT
What do you mean by "it disappears"? Do you get an error?

Signature

Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
 -- www.VBOffice.net --

Am Thu, 23 Nov 2006 15:41:01 -0800 schrieb Nick_NZ:

> Hi,
>
[quoted text clipped - 4 lines]
> I have no idea to why this is occurring, and any help would be greatly
> appreciated.
Nick_NZ - 26 Nov 2006 20:18 GMT
Hi,

The rule fails and a message appears that outlook can not locate the code.
When I go into the VB editor the code is not there at all. This problem is
very weird as the code will just not be there for no apparent reason.

> What do you mean by "it disappears"? Do you get an error?
>
[quoted text clipped - 8 lines]
> > I have no idea to why this is occurring, and any help would be greatly
> > appreciated.
Michael Bauer [MVP - Outlook] - 27 Nov 2006 06:17 GMT
Can you enable VBA again via Help/About/Deactivated Items? Often that's
caused by VBA code that tries to instantiate a new Outlook Application
object, e.g. by CreateObject.

Signature

Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
 -- www.VBOffice.net --

Am Sun, 26 Nov 2006 12:18:01 -0800 schrieb Nick_NZ:

> Hi,
>
[quoted text clipped - 14 lines]
>>> I have no idea to why this is occurring, and any help would be greatly
>>> appreciated.
Nick_NZ - 27 Nov 2006 19:35 GMT
Hi,

There is nothing in the disbaled items list. I can't find a deactivated
items, am I looking in the right place? Can you guys think of anything else,
I have been trying to solve this issue for about 2 months now! :(

Can you enable VBA again via Help/About/Deactivated Items? Often that's
caused by VBA code that tries to instantiate a new Outlook Application
object, e.g. by CreateObject.

> Can you enable VBA again via Help/About/Deactivated Items? Often that's
> caused by VBA code that tries to instantiate a new Outlook Application
[quoted text clipped - 19 lines]
> >>> I have no idea to why this is occurring, and any help would be greatly
> >>> appreciated.
Michael Bauer [MVP - Outlook] - 28 Nov 2006 05:51 GMT
Could you please show the code?

Signature

Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
 -- www.VBOffice.net --

Am Mon, 27 Nov 2006 11:35:01 -0800 schrieb Nick_NZ:

> Hi,
>
[quoted text clipped - 29 lines]
>>>>> I have no idea to why this is occurring, and any help would be greatly
>>>>> appreciated.
Nick_NZ - 28 Nov 2006 19:08 GMT
Here it is:

Sub MakeTaskFromMail(olMail As Outlook.MailItem)
   Dim objTask As Outlook.TaskItem
   
   Set objTask = Application.CreateItem(olTaskItem)
   With objTask
       .Subject = olMail.Subject
       .DueDate = DateAddW(olMail.SentOn, 5)
       .ReminderTime = DateAddW(olMail.SentOn, 4)
       .Importance = olImportanceHigh
       .Body = olMail.Body
   End With
   
   Call CopyAttachments(olMail, objTask)
   
   olMail.Delete
   
   objTask.Save
   
   Set objTask = Nothing
   
End Sub

Sub CopyAttachments(objSourceItem, objTargetItem)
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set fldTemp = fso.GetSpecialFolder(2) ' TemporaryFolder
  strPath = fldTemp.Path & "\"
  For Each objAtt In objSourceItem.Attachments
     strFile = strPath & objAtt.FileName
     objAtt.SaveAsFile strFile
     objTargetItem.Attachments.Add strFile, , , objAtt.DisplayName
     fso.DeleteFile strFile
  Next

  Set fldTemp = Nothing
  Set fso = Nothing
End Sub

'========================================================================================================='
'The follwoing code was obtained from:
http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B198505
'========================================================================================================='

'========================================================'
' The DateAddW() function provides a workday substitute  '
' for DateAdd("w", number, date). This function performs '
' error checking and ignores fractional Interval values. '
'========================================================'
Function DateAddW(ByVal TheDate, ByVal Interval)

  Dim Weeks As Long, OddDays As Long, Temp As String

  If VarType(TheDate) <> 7 Or VarType(Interval) < 2 Or _
             VarType(Interval) > 5 Then
     DateAddW = TheDate
  ElseIf Interval = 0 Then
     DateAddW = TheDate
  ElseIf Interval > 0 Then
     Interval = Int(Interval)

  ' Make sure TheDate is a workday (round down).

     Temp = Format(TheDate, "ddd")
     If Temp = "Sun" Then
        TheDate = TheDate - 2
     ElseIf Temp = "Sat" Then
        TheDate = TheDate - 1
     End If

  ' Calculate Weeks and OddDays.

     Weeks = Int(Interval / 5)
     OddDays = Interval - (Weeks * 5)
     TheDate = TheDate + (Weeks * 7)

 ' Take OddDays weekend into account.

     If (DatePart("w", TheDate) + OddDays) > 6 Then
        TheDate = TheDate + OddDays + 2
     Else
        TheDate = TheDate + OddDays
     End If

     DateAddW = TheDate
  Else                         ' Interval is < 0
     Interval = Int(-Interval) ' Make positive & subtract later.

  ' Make sure TheDate is a workday (round up).

     Temp = Format(TheDate, "ddd")
     If Temp = "Sun" Then
        TheDate = TheDate + 1
     ElseIf Temp = "Sat" Then
        TheDate = TheDate + 2
     End If

  ' Calculate Weeks and OddDays.

     Weeks = Int(Interval / 5)
     OddDays = Interval - (Weeks * 5)
     TheDate = TheDate - (Weeks * 7)

  ' Take OddDays weekend into account.

     If (DatePart("w", TheDate) - OddDays) > 2 Then
        TheDate = TheDate - OddDays - 2
     Else
        TheDate = TheDate - OddDays
     End If

     DateAddW = TheDate
   End If

End Function

'Private Sub Application_ItemSend(ByVal Item As Object, Cancel As
Boolean)End Sub'

Cheers,
Nick

> Could you please show the code?
>
[quoted text clipped - 34 lines]
> >>>>> I have no idea to why this is occurring, and any help would be greatly
> >>>>> appreciated.
Michael Bauer [MVP - Outlook] - 29 Nov 2006 06:41 GMT
Frankly, I don't know what's going on. Maybe Outlook (sometimes) doesn't
like that you delete olMail within the rule?

Signature

Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
 -- www.VBOffice.net --

Am Tue, 28 Nov 2006 11:08:01 -0800 schrieb Nick_NZ:

> Here it is:
>
[quoted text clipped - 34 lines]
>    Set fso = Nothing
> End Sub

'========================================================================================================='
> 'The follwoing code was obtained from:
> http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B198505 '

'========================================================================================================='

> '========================================================'
> ' The DateAddW() function provides a workday substitute  '
[quoted text clipped - 112 lines]
>>>>>>> I have no idea to why this is occurring, and any help would be greatly
>>>>>>> appreciated.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.