Outlook Outlook macros not working until VBA editor is opened

Joined
Jun 18, 2012
Messages
3
Reaction score
0
I have created a rule for outlook to ask me where to save my sent emails (actually, I copied from somewhere in the web) by pasting some code into ThisOutlookSession- see below.

I have digitally signed the macro, and it works fine. But once I close outlook, it stops working.

If i restart outlook, the macro does not work until I open VBA (Alt+f11), and then it works fine until I close Outlook.

The behaviour is independent from the macro setting. I have checked and when I start Outlook, the VBA add-in is active. I did also checked the process has being stopped using task manager as it is suggested in other places.

I would like to make sure the code is active once i start Outlook as ii is a pain to have to open VBA every day, particularly as i tend to forget...


Private Sub Application_ItemSend(ByVal Item As Object, _
Cancel As Boolean)
Dim objNS As NameSpace
Dim objFolder As MAPIFolder
On Error Resume Next
Set objNS = Application.Session
If Item.Class = olMail Then
Set objFolder = objNS.PickFolder
If Not objFolder Is Nothing And _
IsInDefaultStore(objFolder) And _
objFolder.DefaultItemType = olMailItem Then
Set Item.SaveSentMessageFolder = objFolder
Else
Set objFolder = _
objNS.GetDefaultFolder(olFolderSentMail)
Set Item.SaveSentMessageFolder = objFolder
End If
End If
Set objFolder = Nothing
Set objNS = Nothing
End Sub
Public Function IsInDefaultStore(objOL As Object) As Boolean
Dim objApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objInbox As Outlook.MAPIFolder
Dim blnBadObject As Boolean
On Error Resume Next
Set objApp = objOL.Application
If Err = 0 Then
Set objNS = objApp.Session
Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
Select Case objOL.Class
Case olFolder
If objOL.StoreID = objInbox.StoreID Then
IsInDefaultStore = True
Else
IsInDefaultStore = False
End If
Case olAppointment, olContact, olDistributionList, _
olJournal, olMail, olNote, olPost, olTask
If objOL.Parent.StoreID = objInbox.StoreID Then
IsInDefaultStore = True
Else
IsInDefaultStore = False
End If
Case Else
blnBadObject = True
End Select
Else
blnBadObject = True
End If
If blnBadObject Then
MsgBox "This function isn't designed to work " & _
"with " & TypeName(objOL) & _
" objects and will return False.", _
, "IsInDefaultStore"
IsInDefaultStore = False
End If
Set objApp = Nothing
Set objNS = Nothing
Set objInbox = Nothing
End Function

 
Joined
Mar 20, 2012
Messages
764
Reaction score
4
I know you said that its operation is independent of the macro security setting, but have you tried setting that temporarily to Allow all Macros to see if it makes a difference?
 
Joined
Jun 18, 2012
Messages
3
Reaction score
0
Yes, I have tried all different macro settings but to no avail. It is like the VBA is not active until I open the VBA editor, but I have checked and once I start Outlook, the VBA add in is active even if I haven't opened the VBA editor.
 
Joined
Jun 18, 2012
Messages
3
Reaction score
0
Poor way to do business mate.

Anyone else got an idea that does not include a pay per the minute, over the phone solution?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top