PropertyAccessor error - vb.net

I have an Outlook 2007 add-in made in Visual Basic with Visual Studio 2010. I developed this quite a long time ago and it has always worked fine. I detect embedded images using the attachment PropertyAccessor. I now have to go back and make some changes and am running into the following problem. Attempting get the property now gives me the following error (it never did before)
The property "http://schemas.microsoft.com/mapi/proptag/0x37140003" is unknown or cannot be found. Other properties I can get fine. I have seen other posts with the same error which mention that the PR_ATTACHMENT_HIDDEN property is not set. I don't understand this as the attachment is an ordinary jpg sent by me from another account. If I build the add-in and install in Outlook 2016 it works just fine. What I find strange is that it used to work with no errors. I don't know if it makes any difference but it is running in VirtualBox.
Any Ideas would be welcome.

Keep in mind that PropertyAccessor.GetProperty behavior changed (in Outlook 2010?) when it comes to properties that are not present - GetProperty will now raise an exception instead of returning null.
You need to expect and handle that exception - no MAPI property should be expected to be present. In your particular case, missing PR_ATTACHMENT_HIDDEN is the same as PR_ATTACHMENT_HIDDEN == false.
Take a look at the available MAPI properties on the attachment in OutlookSpy (I am its author) - select the message, click IMessage button on the OutlookSpy ribbon, go to the GetAttachmentTable tab, double click on the attachment.

Related

How to Edit Custom (Server) Document Properties - Microsoft Word 2013 (VB Macros)

A Microsoft Word 2013 document at work has the Document Information Panel (DIP) displayed by default, with what is listed as "Document Properties - Server".
I'm trying to make a VB Macro that will involve editing these custom properties. However they don't seem to exist in ActiveDocument.CustomDocumentProperties, or ActiveDocument.BuiltInDocumentProperties. I know this because I ran through the list, displaying them one by one, as well as searching them by name.
The first property on the DIP called 'Title' showed up (in the latter list), but none of the other properties. It's worth noting that some are dropdowns, and one is a date with a calendar feature. I should also mention that I get a Run-time error near the end of the list of BuiltInDocumentProperties.
Is there another list where I can access these server properties, or some other issue that I'm overlooking? Any help would be appreciated.
I was able to find them. They are listed in ActiveDocument.ContentTypeProperties

Word opens for real when trying to fill-in the blanks dynamically?

I'm currently using Word documents as templates where blanks have to be filled dynamically/programmatically in PwoerBuilder.
This has always worked fine until the company moves on Windows 7.
In short, the Word application is opened and made invisible.
Word.Application.Visible = false
Except that sometimes, and I don't know why, once the template is accessed, Word opens itself just as if I had double-clicked the template byself through the Explorer - but I didn't.
So, it asks whether I want to open it in read-only mode, since the application already has a handle on the file. And even if I click [Cancel] not to open the file, Word opens with no document, then the application crashes.
It reports PowerBuilder System Error 35.
Error Number 35.
Error text = Error calling external object function open at line 24 in function of_fusion of object n_cst_9999.
The external object that the application is trying to call a function against is Word.
oleobject lole_word
lole_word = create oleobject
lole_word = ConnectToNewObject("Word.Application")
lole_word.Documents.Open("templatefile.docx")
It may work for a few documents, and after a few, the problem comes up. This is the first time ever I meet with this issue.
I'll be glad to answer anyone's question who's trying to help.
Will, you may try setting DisplayAlerts and FeatureInstall properties on Word Application object.
That hid most of word alerts for us. (The code is from C# project and may not be exactly what you need)
Word.Application.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;
Word.Application.FeatureInstall = 0;
You may also try making a copy of the file before opening it to avoid accessing same .docx from different threads - if that may be the case.

Outlook 2007 - VBA macro in NormalEmail.dotm

I have a Word 2007 template that I use as Normal.dotm, which has corporate theme, styles, etc., plus a tiny bit of macro code that overrides the default behaviour of the bullet & number buttons on the ribbon.
I'd now like to use this same template when creating emails in Outlook 2007. I've tried just copying my Normal.dotm to NormalEmail.dotm, and to an extent this works, but although my macro is correctly invoked when I press the bullet/number buttons in the email editor, it gives an error:
Run time error 429: ActiveX component can't create object
On further investigation, it seems that anything I do within my macro that references an object in the normal Word object model (Application, Selection, etc.) causes this error. So, even if my macro consists of the following, it still fails:
MsgBox TypeName(Application)
I have an inkling that this is because I'm running in the context of Outlook, not Word, and so perhaps there is no (Word) application, or any of the objects associated with it. I know that the email editor in Outlook is Word-but-not-as-we-know-it-Jim.
Having said that, I did discover that ThisDocument does return a valid Document object; unfortunately, it corresponds to the template itself, not the email being edited.
By trial and error, I've discovered that I can get at the Document corresponding to the email by the following circuitous route (this displays the text in the email):
MsgBox ThisDocument.MailEnvelope.Item.Application.ActiveInspector.WordEditor.Content.Text
However, this code also seems to cause Outlook to crash - not at the time, but later, when you close Outlook.
At this point, I'm just about ready to admit defeat. No doubt the "correct" way to create macros in Outlook is to create them in Outlook itself, but from my limited experience, that's just horrible. (You can create macros in VBA, but you can't deploy them; or, you can create them in VSTO, but then you need an installer rather than simply deploying a template).
So. Any ideas out there that would let me do all that I hoped to do?
Override the behaviour of the bullet/number buttons on the ribbon in the email editor.
Deploy the macros in the NormalEmail.dotm file, rather than having to "install" them.
Not crash Outlook.
Have you tried adding the reference in the VBA editor to the Microsoft Outlook Object Library?
In Outlook 2007 you might also have to add VBA references to "Microsoft Word 12.0 Object Library" and maybe "Microsoft Forms 2.0 Object Library". Different versions may apply for other version years.
In addition, in the macro/code you have to set the objects to get/use the correct methods and properties.
I'm not an OO programmer and usually copy code from elsewhere and modify for my need so I can't help much more than what I said above. (And one of my macros is also giving me the same 429 error you get.)

How to determine if 'SaveChanges:=wdDoNotSaveChanges' was passed to Interop.Word.Document.Close()

I have an issue with an Office addin I'm working on, which is implemented for Office 2003 & 2007. The addin is written in VB.NET 3.5 using VSTO.
The problem comes from some external code which automates a mail merge, opening the mail merge template, merging and then closing the template document. The close is done with this code:
objWord.Documents(sDoco).Close SaveChanges:=wdDoNotSaveChanges, OriginalFormat:=wdPromptUser
Because of some logic in my addin, instigated from the Interop.Word.Application.DocumentBeforeClose event, a message box is opened which prevents the Office document from closing, which breaks the automation.
Is there a way for me to determine the SaveChanges parameter (if any) on a Close within an Office.Interop.Word.Application event, such as DocumentBeforeClose? I'm trying to capture this parameter and determine if it's set to wdDoNotSaveChanges so that I can work around this problem.
I'm pretty sure you get the DocumentSave event BEFORE the DocumentBeforeClose, so set a flag in it, and if that flag is set at close, you know the doc has been saved, but if not, it was not. I've had to do similar things to know whether a Document was SAVED-AS vs just SAVED.
I'm not aware of any way to interrogate the state of that parameter from DocumentBeforeClose.

"'SnippetElement' is null or not an object" error when submitting InfoPath 2010 form

I have an InfoPath 2010 web form that was upgraded from a 2007 version. The 2007 version worked fine.
When the form submits, it saves to a SharePoint 2010 document library - it is being saved correctly.
However, I get a javascript error, "'SnippetElement' is null or not an object". I've checked all my submit options and they look OK. Even republished the form several times to no avail.
Anyone had this error before and can tell me how to stop it?
For anyone who comes across this post, I eventually solved the problem (though I think there is a bug in Infopath or SharePoint that caused the issue).
My form, and several others I have found since were using a "Submit" action to post the data to the list.
By changing the form to using a "Rules and Custom Code" action that is configured to submit using a data connection instead, the JavaScript error no longer occurs.
As these forms worked in 2007, clearly something has changed in 2010 that breaks them.