MailMerge not working on Office 2016 - progress-4gl

I have one program which uses mailmerge in Word and it works perfectly in office 2007 and tested in 2010. But in office 2016 it throws an error
Code is below
ASSIGN lv_cDocument = fiFile. /* chosen from program select */
ASSIGN lv_cDataFile = "C:\a\data.dat".
ASSIGN lv_cMailMergeFile = "C:\a\dataOutput.doc".
MailMerge(lv_cDocument, /* Main Document */
lv_cDataFile, /* File that holds all the data */
lv_cMailMergeFile, /* File to hold new mail merge document */
NO).
DEFINE VARIABLE oWord AS COM-HANDLE NO-UNDO.
CREATE "Word.Application" oWord.
oWord:Documents:Open("C:\a\dataOutput.doc").
oWord:Visible = True.
RELEASE OBJECT oWord.
Any thoughts what is "new" in new office so i can modify my program that it works on all version of MS-Offices?

When doing COM, both applications (OrenEdge and Word) should be same "bitness". To be safe, both products should be 32 bit - I'm not 100% sure if 64 bit Word supports Automation interfaces.
The alternative on 11.6 might be the Interop API's (.NET): https://msdn.microsoft.com/de-de/library/microsoft.office.interop.word(v=office.11).aspx

The problem was in Word options.
Steps to resolve the auto launch errors:
Open MS Word.
Click on File > Options.
In the General section under Start up options, uncheck the "Open e-mail attachments and other uneditable files in reading view" box.
Close Word and try to export and auto launch your document again. It may take a couple of tried for Word to realize the setting has been changed.
Source

Problem for me was although it shows only ms office 2016 is installed and only one version of it. When I looked under start and went to outlook it showed the normal icon for outlook and the another one that said outlook 2016.
So I set up the user profile on the normal outlook, made sure that is open and not the outlook 2016 one and now the mail merge works for me.
Hope this helps someone out.

Related

Numbering is missing on body.getOoxml() in Word 2016 MSO

Using body.getOoxml() in an add-in for Word 2016 does not include the numbering package part. This leads to errors when executing insertooxml() since the API creates new numbering definitions which are wrong or default to the standard (as 1,2,3 etc.). Hence numberings that have other logic, like lower letters or roman letters, will be set back to the standard on executing insertooxml().
This applies to Word 2016 MSO which still uses IE 11 in add-ins. (nothing we can do about that).
In Word for M365 it works correctly.
The Word version in use is 16.0.5369.1000 MSO 16.0.5366.1000 32-Bit (Running on Windows 10)
We currently use Office-js version 1.1.82 (the newest 1.1.83-custom.0 has a bug that throws an exception on insertooxml in Word 2016)
We need this for our solution which removes sensitive data from word documents. Since Word Js Api 1.1 does not include hyperlinks, we need to operate on ooxml to fix hyperlinks as well.
Steps to recreate:
Create a new word document
Add one or two titles
Change title numbering to "a,b,c"
Execute the following code in an add-in:
var body = context.document.body;
var body_ooxml = body.getOoxml();
await context.sync();
var body_ooxml_value = body_ooxml.value;
body.insertOoxml(body_ooxml_value, Word.InsertLocation.replace);
await context.sync();
What I expected:
The content of the document should remain the same. Without any changes to the numbering
current findings
I made several tests and found out that in Word 2016 MSO, getOOXML does not return the numbering - even though the file numbering.xml exists and is correct. After executing insertOoxml it seems as if the api is trying to re-create the numbering from scratch which leads to an overwrite in numbering.xml that includes standard numbering (1,2,3).
I don't see a workaround (but would be happy for any advice).This seems to be a product bug and needs to fixed.
Just FYI, in case you didn't know: Microsoft no longer requires support for IE in add-ins that are distributed through AppSource. That said, it does seem to be a bug, so you could create a bug issue on the office-js repo. But I don't think a bug in an Office version that old will have a high priority.

Automatically download emails from Outlook with SAS or Outlook rule

I am trying to create a program to automatically download the attached files that are sent to us from a certain email and then transform the delimiter with SAS, of those csv that are attached to us and pass those csv through a flow that I have already created.
I have managed to create a program that treats the csv as I want and the delimiter that I want, the problem is that when it comes to automating the download of files from Outlook it does not work.
What I have done is create a rule with the following VB code that I found on the internet:
Public Sub SaveAttachmentsToDisk(MItem As Outlook.MailItem)
Dim oAttachment As Outlook.Attachment
Dim sSaveFolder As String
sSaveFolder = "C:\Users\ES010246\Desktop"
For Each oAttachment In MItem.Attachments
oAttachment.SaveAsFile sSaveFolder & oAttachment.DisplayName
Next
End Sub
I have changed the path to my personal path where i want the files are downloaded.
website: https://es.extendoffice.com/documents/outlook/3747-outlook
The problem is that this code does not work for me, it does absolutely nothing for me and no matter how much I search the internet, only this code appears.
Is there any other way to do with SAS what I want? What is it to automatically download 8 csv files sent to me by Outlook, or has someone experienced the same thing as me with VBA?
I have followed all the steps about 7 times so I think the error is not in copying the code or selecting certain options wrong, in fact I had copied and pasted the code and later I modified the path where I wanted those to be saved. files but it doesn't work, does anyone know why?
I will be tremendously grateful, thank you very much for everything!
First of all, you need to make sure the file name and path doesn't include forbidden symbols.
The VBA macro used for a rule in Outlook is absolutely valid except that a mail item may contain the attached files with the same name, so a file saved to the disk may be overwritten (saved with the same name). That's why I'd suggest generating a file name with your own unique IDs making sure that DisplayName property is not empty and has a valid name what can be used for file names (exclude forbidden symbols).
Also you may consider handling the NewMailEx event of the Application class which is fired when a new message arrives in the Inbox and before client rule processing occurs. Use the Entry ID returned in the EntryIDCollection string to call the NameSpace.GetItemFromID method and process the item. This event fires once for every received item that is processed by Microsoft Outlook. The item can be one of several different item types, for example, MailItem, MeetingItem, or SharingItem.
The Items.ItemAdd event can be helpful when items are moved to a folder (from Inbox). This event does not run when a large number of items are added to the folder at once.

receive windows popup message or alert for a specific incoming mail

we have following problem. we need an extra windows popup message or baloon tip message in windows, if a mail from a specific sender arrives in outlook. are there any examples in powershell or any other programms recommend?
thanks in advance
You can use basic Outlook rules to create a desktop alert with any given condition, no need for any script or special program
If you want, the rule can also run a script and then you can do whatever you want there
From the following webpage, https://www.slipstick.com/outlook/rules/outlooks-rules-and-alerts-run-a-script/
Using VBA
Something like this:
Public Sub ShowMessage(Item As Outlook.MailItem)
'code
End Sub
The argument must by type MailItem or MeetingItem for the subroutine to be available in the Rules Wizard in Outlook 2007. In Outlook 2010 and 2013 (and up), PostItem also works.
Open Rules Wizard. In Outlook 2010 and 2013, it's on Outlook's Home ribbon,
Rules > Manage Rules & Alerts. Look on the Tools menu in older versions.
Open Rules Wizard
Click New Rule.
Select Apply Rule on messages I receive and click Next.
Select your conditions and click Next.
Select Run a script action (near the bottom).
The finished run a script rule
Click on a script.
Select the script
Select your script, click OK.
Click Next then finish the rule.
There are several ways to get the job done:
Create a rule in Outlook manually and assign a VBA macro which can be triggered by the rule. For example:
Public Sub TestRule(Item As Object)
If(Item.SenderEmailAddress = "eugene#test.com") Then
MsgBox "Got email!"
End If
End Sub
Use the VBA routine for handling incoming emails. The NewMailEx event fires when a new message arrives in the Inbox and before client rule processing occurs. You can use the Entry ID returned in the EntryIDCollection array to call the NameSpace.GetItemFromID method and process the item. This event fires once for every received item that is processed by Microsoft Outlook. The item can be one of several different item types, for example, MailItem, MeetingItem, or SharingItem. The EntryIDsCollection string contains the Entry ID that corresponds to that item.
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
Dim mai as Object
Set mai = Application.Session.GetItemFromID(EntryIDCollection)
If(mai.SenderEmailAddress = "eugene#test.com") Then
MsgBox "Got email!"
End If
End Sub

VSTO Load On Demand

I have a Word 2016 VSTO that I developed using VS2015 and deployed to a Windows 10 machine using InstallShield. If I set the LoadBehavior to 3 it loads and works fine.
What I need is for it load on demand. I've tried just setting LoadBehavior to 9 but no dice. The web application that is creating the Word document (that ultimately loads the VSTO) was originally written for Word 2010 and is embedding the VSTO path in the Word document with an added GUID (C:\myAddIn.vsto|GUID|vstolocal). Opening the document created by the web application in Word 2016 throws this error when the VSTO tries to load:
Microsoft.VisualStudio.Tools.Applications.Runtime.CannotCreateStartupObjectException:
Could not create an instance of startup object myAddin.ThisAddIn
Any tutorials I've seen for VS2013/2015 do not reference embedding a GUID in the VSTO path; just set the LoadBehavior to 9.
There is no Publisher listed in File -> Options ->AddIns. The VSTO is listed under Inactive AddIns which I would expect until it is loaded on demand.
Any help is greatly appreciated.
If you want code to only execute with certain documents, such as you describe (from Comments)
I only want the AddIn to load for Word documents created by the web
application. Opening Word from the Start menu should not load the
AddIn.
then it is probably better to use a document-level customization, rather than an add-in.
The code attached to a document-level customization will load with the document, and unload when the document is closed. It's possible to create a document-level customization and distribute the document, or to attach the code at a later time using VSTO's ServerDocument class.
Since in your case the documents are being generated by a web app, using ServerDocument is indicated.
Here's the main content of the MSDN article:
=============================================
To attach managed code extensions to a document
In a project that does not require Microsoft Office, such as a console application or Windows Forms project, add a reference to the
Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll and
Microsoft.VisualStudio.Tools.Applications.Runtime.dll assemblies.
Add the following Imports or using statements to the top of your code file.
using Microsoft.VisualStudio.Tools.Applications;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
Call the static AddCustomization method.
The following code example uses the AddCustomization overload. This overload takes the full path of the document and a Uri that specifies the location of the deployment manifest for the customization you want to attach to the document. This example assumes that a Word document named WordDocument1.docx is on the desktop, and that the deployment manifest is located in a folder that is named Publish that is also on the desktop.
string documentPath = System.Environment.GetFolderPath(
Environment.SpecialFolder.Desktop) + #"\WordDocument1.docx";
int runtimeVersion = 0;
try
{
runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath);
// Make sure that this document does not yet have any Visual Studio Tools
// for Office customizations.
if (runtimeVersion == 0)
{
string deployManifestPath = System.Environment.GetFolderPath(
Environment.SpecialFolder.Desktop) + #"\Publish\WordDocument1.vsto";
Uri deploymentManifestUri = new Uri(deployManifestPath);
ServerDocument.AddCustomization(documentPath, deploymentManifestUri);
System.Windows.Forms.MessageBox.Show("The document was successfully customized.");
}
else
{
System.Windows.Forms.MessageBox.Show("The document is already customized.");
}
}
catch (FileNotFoundException)
{
System.Windows.Forms.MessageBox.Show("The specified document does not exist.");
}
catch (DocumentNotCustomizedException ex)
{
System.Windows.Forms.MessageBox.Show("The document could not be customized.\n" +
ex.Message);
}
Build the project and run the application on the computer where you want to attach the customization. The computer must have the Visual Studio 2010 Tools for Office Runtime installed.
Did you try to set LoadBehaviour to 0x10 => Load first time, then load on demand? This should make Office load your addin the first time you execute it and internally cache it. It will then change the value to 0x9... The subsequent times, the app will load on demand.

how to stop macros running when opening a Word document using OLE Interop?

As the title suggests, I have a .Net application which uses interop to open documents in Word. I have set
app.AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityForceDisable
before opening the document. According to the documentation, thhis "Disables all macros in all files opened programmatically, without showing any security alerts"
However, when I attempt to open one specific document I get a dialog box on the screen that says "could not load an object because it is not available on this machine". It's a customer document but I believe it contains a macro with references to a COM object which I don't have installed.
Am I doing something stupid? is there any way to actually disable macros when opening a Word document?
Try:
WordBasic.DisableAutoMacros 1
Bizarrely, this relies on a throwback to pre-VBA days, but still seems to be the most-reliable way to ensure that no auto macros are triggered (in any document - you may want to turn it back using the parameter "0").
I recently had a project where I had to process 6,000 Word templates (yes, templates, not documents) many of which had oddball stuff like macros, etc. I was able to process all but 6 using this technique. (I never did figure out what the problem was with those 6).
EDIT: for a discussion of how to call this from C#, see: http://www.dotnet247.com/247reference/msgs/56/281785.aspx
For c# you can use
(_wordApp.WordBasic as dynamic).DisableAutoMacros();
The whole code I'm using is:
using Word = Microsoft.Office.Interop.Word;
private Word.Application _wordApp;
...
_wordApp = new Word.Application
{
Visible = false,
ScreenUpdating = false,
DisplayAlerts = Word.WdAlertLevel.wdAlertsNone,
FileValidation = MsoFileValidationMode.msoFileValidationSkip
};
_wordApp.Application.AutomationSecurity = MsoAutomationSecurity.msoAutomationSecurityForceDisable;
(_wordApp.WordBasic as dynamic).DisableAutoMacros();