T
Tom
Hi,
I am pretty new on Office Development with VBA/script. I appriciate any
suggestions and/or advices.
We have a project. The project is to check the URLs in the content of
emails. When user select a mail item in Outlook we grab all the URLs. If any
of them is dangerous then we will put notes to tell the user that this URL is
dangerous.
The project has 2 parts. The first part in C++ code. It gets the IDispatch
object from email inspector window. If the email editor is wordEditor then
let's just assume that the IDispatch object is a wordEditor object. The C++
code invoke javaScript function with wordEditor as parameter.
Another part is in javaScript. One of the function in javaScript take
wordEditor as parameter. This function will check the URLs in the wordEditor.
If any of any URL is dangerous then insert warning text around the URL.
The logic is from wordEditor we get myDocument =
wordEditor.Application.ActiveDocument. From myDocument we can get myRange =
myDocument.Range(0, 0); From myRange we call myEditor = myRange.Add(-1);
========================================
function CheckURLs(wordEditor)
{
var myDocument = wordEditor.Application.ActiveDocument;
var myRange = myDocument.Range(0, 0);
var myEditor = myRange.Add(-1); // it works fine on Outlook 2007 but not
2010
....
// unrelated code omited
....
}
========================================
Previously with Outlook 2007 there is no problem with the javaScript code
operated upon wordEditor. However in Outlook 2010 the problem line to Add(-1)
raise exception from javaScript. The exception does not give me much meaning.
So I wrote testing code in C++ with IDispatch::GetIDsOfNames(...) and
IDispatch::Invoke(...) to simulate the logic on javaScript. The exception now
gave me some hints - "This method is not available for the document is
read-only, can not check-in". I've tried some other ways to change content
with VBA/javaScript, finally I find a way to change it. Thanks Sue for
helping me solve the problem on "Can not change email body content on Outlook
2010". The VBA code is like:
=============================================
Sub test()
Dim ns As NameSpace
Dim Inbox As MAPIFolder
Dim Item As Object
Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
Set Item = Inbox.Items.Item(1)
Item.Body = "Test" & Item.Body
Item.Save
End Sub
=============================================
Now the problem is that the way I found to change the content using an obect
as MailItem. However the parameter passing to the javaScript is wordEdit. So
the question is that how to get the MailItem object from wordEditor?
Thanks in advance!
Tom
I am pretty new on Office Development with VBA/script. I appriciate any
suggestions and/or advices.
We have a project. The project is to check the URLs in the content of
emails. When user select a mail item in Outlook we grab all the URLs. If any
of them is dangerous then we will put notes to tell the user that this URL is
dangerous.
The project has 2 parts. The first part in C++ code. It gets the IDispatch
object from email inspector window. If the email editor is wordEditor then
let's just assume that the IDispatch object is a wordEditor object. The C++
code invoke javaScript function with wordEditor as parameter.
Another part is in javaScript. One of the function in javaScript take
wordEditor as parameter. This function will check the URLs in the wordEditor.
If any of any URL is dangerous then insert warning text around the URL.
The logic is from wordEditor we get myDocument =
wordEditor.Application.ActiveDocument. From myDocument we can get myRange =
myDocument.Range(0, 0); From myRange we call myEditor = myRange.Add(-1);
========================================
function CheckURLs(wordEditor)
{
var myDocument = wordEditor.Application.ActiveDocument;
var myRange = myDocument.Range(0, 0);
var myEditor = myRange.Add(-1); // it works fine on Outlook 2007 but not
2010
....
// unrelated code omited
....
}
========================================
Previously with Outlook 2007 there is no problem with the javaScript code
operated upon wordEditor. However in Outlook 2010 the problem line to Add(-1)
raise exception from javaScript. The exception does not give me much meaning.
So I wrote testing code in C++ with IDispatch::GetIDsOfNames(...) and
IDispatch::Invoke(...) to simulate the logic on javaScript. The exception now
gave me some hints - "This method is not available for the document is
read-only, can not check-in". I've tried some other ways to change content
with VBA/javaScript, finally I find a way to change it. Thanks Sue for
helping me solve the problem on "Can not change email body content on Outlook
2010". The VBA code is like:
=============================================
Sub test()
Dim ns As NameSpace
Dim Inbox As MAPIFolder
Dim Item As Object
Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
Set Item = Inbox.Items.Item(1)
Item.Body = "Test" & Item.Body
Item.Save
End Sub
=============================================
Now the problem is that the way I found to change the content using an obect
as MailItem. However the parameter passing to the javaScript is wordEdit. So
the question is that how to get the MailItem object from wordEditor?
Thanks in advance!
Tom