jana
asked on
What is causing a VBA script, in ThisOutlookSession to not work in Outlook 2007
We have a script (see below) placed in "ThisOutlookSession", under "Microsoft Office Outlook Objects" section, which after a while it tops working.
However, we exit Outlook and started again and it works. The point is, the script just stops working. We also place a stop and the control never goes to thos lines again, but when Outlook restarted, it works again.
However, we exit Outlook and started again and it works. The point is, the script just stops working. We also place a stop and the control never goes to thos lines again, but when Outlook restarted, it works again.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanx. How do I run startup application?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Did it and got this error message:
-------------------------- -
Microsoft Visual Basic
-------------------------- -
Compile error:
Sub or Function not defined
-------------------------- -
OK Help
-------------------------- -
--------------------------
Microsoft Visual Basic
--------------------------
Compile error:
Sub or Function not defined
--------------------------
OK Help
--------------------------
The sub is in your snippet ... and it is what is run when you start the application in order to initialise the event handler. Personally i'm confused
Chris
Chris
ASKER
The sub "Application_Startup" does exist and as recommended, in the immediate window I typed the Application_Startup and then pressed Enter key.
At this point, the sub m_Inspectors_NewInspector (see ID: 38259898) now doesn't work.
The curious thing is that other VBA scripts outside ThisOutlookSession (that is, Forms and Modules), works perfectly.
Please advice.
At this point, the sub m_Inspectors_NewInspector (see ID: 38259898) now doesn't work.
The curious thing is that other VBA scripts outside ThisOutlookSession (that is, Forms and Modules), works perfectly.
Please advice.
ASKER
Just exited & restarted Outlook and works ok again.
Hope we can find the cause & solution.
Thanx in advance.
Hope we can find the cause & solution.
Thanx in advance.
The other subs will be fine as long as they do not use events, whereas the event handler should be re-initialised via startup.
Hopefully someone will have solution tho I will try to think why the startup sub isn't initialising it here
Chris
Hopefully someone will have solution tho I will try to think why the startup sub isn't initialising it here
Chris
ASKER
ok thanx; we are also googling to see if anything
ASKER
Maybe this info can help:
We were testing to see what is causing it and pass the info to the expert. After restarting Outlook, we ran a macro not from ThisOutlookSession (the other subs). Afterward click for new email so it can fire the macro that places an email in the BCC field (see code in ID: 38259898) and it didn't work; was disabled again the events.
So there is something in the sub that is causing dishable the events. Here is the code that we ran prior:
Please review to see what is causing the event to get lost or disabled?
Thanx
We were testing to see what is causing it and pass the info to the expert. After restarting Outlook, we ran a macro not from ThisOutlookSession (the other subs). Afterward click for new email so it can fire the macro that places an email in the BCC field (see code in ID: 38259898) and it didn't work; was disabled again the events.
So there is something in the sub that is causing dishable the events. Here is the code that we ran prior:
Sub FillColumnSUPPORT()
WhereFrom = 1
Call frmSUPPORT.Show
If OptionSelected = False Then End 'Exit completely if non selected
Dim olkMsg As Outlook.MailItem, olkProp As Object
For Each olkMsg In Application.ActiveExplorer.Selection
If TypeName(olkProp) = "Nothing" Then
Set olkProp = olkMsg.UserProperties.Add("Type", olText, True)
olkProp.Value = SUPPORTSelected
olkMsg.Save
End If
Set olkProp = Nothing
Next
Set olkMsg = Nothing
End Sub
Please review to see what is causing the event to get lost or disabled?
Thanx
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yeah worked! We could get it activated again.
Please advice on our previous post.
Please advice on our previous post.
I have to admit I do not have any clue. You can try adding an ON ERROR RESUME NEXT at the very beginning of the sub, so the sub will not terminate on error. That might help.
On another note, this part of code looks strange:
On another note, this part of code looks strange:
If TypeName(olkProp) = "Nothing" Then
Set olkProp = olkMsg.UserProperties.Add("Type", olText, True)
olkProp.Value = SUPPORTSelected
olkMsg.Save
End If
Set olkProp = Nothing
You can replace that by olkMsg.UserProperties.Add("Type", olText, True) = SUPPORTSelected
olkMsg.Save
which does exactly the same.
ASKER
Understood. How can we make the script work or how to place it in the sub the recommended "ON ERROR RESUME NEXT"
See in your original code you make no assumptions for the object type. Set the type for olkMsg to object, add a test for TypeName(Inspector.Current Item) to ensure you are dealing in fact with a mail item and set olkProp to something ... at present you declare it and then immediately test for nothing ... it will always be nothing unless set to something and on every loop you again set it to nothing so you are not testing for the property as existing before going on to create it as new.
Chris
Sub FillColumnSUPPORT()
WhereFrom = 1
Call frmSUPPORT.Show
If OptionSelected = False Then End 'Exit completely if non selected
Dim olkMsg As object, olkProp As Object
For Each olkMsg In Application.ActiveExplorer.Selection
If TypeName(olkProp) = "Nothing" Then
Set olkProp = olkMsg.UserProperties.Add("Type", olText, True)
olkProp.Value = SUPPORTSelected
olkMsg.Save
End If
Set olkProp = Nothing
Next
Set olkMsg = Nothing
End Sub
Chris
ASKER
We understood from the star, thanx. Where do we pace ON ERROR RESUME and have it set correctly?
You miss the point I think .... Resume next can help albeit slowly for unknown errors but there are some things abo e you can fix which is more efficient
Chris
Chris
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
My mentioning of ON ERROR RESUME NEXT was just for testing purposes, or whenever it is much easier to ignore a (known or unknown) potential error in one or two lines. If it works with the RESUME stuff, we know we have to search for errors somewhere ...
ASKER
Goof observation. We commented the line Call frmSUPPORT.Show and it didn't affect the BCC script; all went ok. We looked in the script and is just a simple message box:
We proceed and uncommented line of Call frmSUPPORT.Show so it can be executed and again the error of disabling ThisOutlookSession.
Private Sub UserForm_Initialize()
'Just display form
End Sub
We proceed and uncommented line of Call frmSUPPORT.Show so it can be executed and again the error of disabling ThisOutlookSession.
ASKER
Question: seeing that all we need is to run "Call ThisOutlookSession.Applica tion_Start up", we placed at the end the sub (see below):
But it gaves us the following error message:
-------------------------- -
Microsoft Visual Basic
-------------------------- -
Compile error:
Method or data member not found
-------------------------- -
OK Help
-------------------------- -
In conclusion, can we just place the "Call" at the end of the sub so it can be activated again??
Sub FillColumnSUPPORT()
WhereFrom = 1
Call frmSUPPORT.Show
If OptionSelected = False Then End 'Exit completely if non selected
Dim olkMsg As Outlook.MailItem, olkProp As Object
For Each olkMsg In Application.ActiveExplorer.Selection
If TypeName(olkProp) = "Nothing" Then
Set olkProp = olkMsg.UserProperties.Add("Type", olText, True)
olkProp.Value = SUPPORTSelected
olkMsg.Save
End If
Set olkProp = Nothing
Next
Set olkMsg = Nothing
'Restart OutlookSession
call ThisOutlookSession.Application_Startup
End Sub
But it gaves us the following error message:
--------------------------
Microsoft Visual Basic
--------------------------
Compile error:
Method or data member not found
--------------------------
OK Help
--------------------------
In conclusion, can we just place the "Call" at the end of the sub so it can be activated again??
If FillColumnSUPPORT is in the same module as Application_Startup, you can just use
call Application_Startup
as the "context" is already set correctly (it works both for me). Though that should not make any difference.
Is the error line really the CALL?
call Application_Startup
as the "context" is already set correctly (it works both for me). Though that should not make any difference.
Is the error line really the CALL?
ASKER
Yes, when the Call is executed, the event is disabled. When I comment it, it not disable.
Note: FillColumnSUPPORT is not in the same module as Application_Startup, rather is "Modules" sections.
Maybe that is why of the error,
Note: FillColumnSUPPORT is not in the same module as Application_Startup, rather is "Modules" sections.
Maybe that is why of the error,
ASKER
Also we did find a way to run Application_Startup from the "Module" section:
- created a public sub in ThisOutlookSession:
Sub AppStartup()
Call Application_Startup
End Sub
- then we call it from FillColumnSUPPORT as follows:
Call ThisOutlookSession.AppStar tup
And no error.
Nevertheless it sometimes work and other it just doesn't.
Any suggestion?
- created a public sub in ThisOutlookSession:
Sub AppStartup()
Call Application_Startup
End Sub
- then we call it from FillColumnSUPPORT as follows:
Call ThisOutlookSession.AppStar
And no error.
Nevertheless it sometimes work and other it just doesn't.
Any suggestion?
ASKER
I think we finally identify why it worked and sometimes it doesn't. We noticed that Application_Startup doesn't work if sub FillColumnSUPPORT is ended in line 4 (see ID: 38261898). But if ended as normal End Sub, line 19, the Application_Startup works.
Please explained and how can we have it to always work prior exiting the sub.
Please explained and how can we have it to always work prior exiting the sub.
ASKER
doesn't work even if i place it as follow, changing the "IF" line:
If OptionSelected = False Then
Call ThisOutlookSession.AppStar tup
End 'Exit completely if non selected
End If
If OptionSelected = False Then
Call ThisOutlookSession.AppStar
End 'Exit completely if non selected
End If
>>> We looked in the script and is just a simple message box:
Assuming there is no other code in the form then it would seem the form is left open all the time so that is likely part of the problem. Exactly what is the intended usage of the form?
Chris
Assuming there is no other code in the form then it would seem the form is left open all the time so that is likely part of the problem. Exactly what is the intended usage of the form?
Chris
ASKER
Is a ListBox since the form has a lot of lines, we deleted everything leaving it empty so as to just display or ".show" the form (this way to assure if it was a specific line). And still the same error.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes it Worked !!!! By restructuring the "If" as recommended made it possible to maintain events enabled.
Thanx!
Thanx!
ASKER
Ok I think with this, we can close the question.
In conclusion, and for future references, is it safe to say that in order for the "Events" not be wiped or disabled, we must contain the control within each sub routine and assure that not to use "If X = False Then End " instead restructure the "If" to continue and have the routine to exit as it supposed to?
Please advice and shed some light in this doubt we have.
Thanx
In conclusion, and for future references, is it safe to say that in order for the "Events" not be wiped or disabled, we must contain the control within each sub routine and assure that not to use "If X = False Then End " instead restructure the "If" to continue and have the routine to exit as it supposed to?
Please advice and shed some light in this doubt we have.
Thanx
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanx a Lot !!!!!
(at this point we are changing all subroutines with this issue. Thank you very much for everything)
(at this point we are changing all subroutines with this issue. Thank you very much for everything)
ASKER
Thanx all!
ASKER
[This a VBA script we use to have the BCC filled with a specific email. unfortunately, after while, it stops working and no BCC is placed when sending, replying or forwarding an email]
Open in new window