SaveAs Method of Workbook Class Failed

Hi,

As mentioned in my previous post I have created a script that creates a Excel xls file for reporting. (VBScript) In debug it works fine but not when it runs as a service. I read this on msdn which worries me and I thought the OL pros might be able to help.

It is the limitation to office design to server-side automation.

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

Is there a way around this?

EDIT: The line of code in question is as follows.
objWorkbook.Saveas "D:\ClientName\Payslips\Proofs\Client - " & aDate, 51

Regards,
S

Not really. What you’re doing, behind the scenes, is launching the Excel application and essentially running the equivalent of a Macro. Excel was never designed to be automated like this, especially by a service like Workflow that may be running with local system privileges. That means Excel may not be completely thread-safe, which could potentially cause memory corruption issues.

Note that the above is the theory of it all. Excel may very well run properly in this context, but the simple fact that Microsoft discourages this type of use should alert you to the fact that they probably know there are some vulnerabilities in doing so.

My question to you is: do you absolutely need an XLS file for reporting or can’t you simply generate a CSV file, which wouldn’t require you to call Excel under the Hood?

Hi Phil,

Apologies for taking a while to respond, I was driving home from work.

Thanks for your insight. Unfortunately I have a new client and I have already shown them the Excel file report to which they approved for their upcoming mailing, so going back would be embarrassing. The script also adds formatting to the xls with cell borders thus creating a table, something a csv wont allow been text based.

I’m not sure what to do now. Never would I have thought of this restriction with MS and automation software.

Can I save the script as a VBS file and run it externally from a Workflow service? I would have to write the data/PostScript totals to a file and modify the script to read said file to use those totals in the xls. Or is this just going to result in the same issue? I’m treading uncharted territory here, so excuse silly suggestions.

Edit2: If I could create a HTML email with a table in the body of the email with totals etc. That would be saving face but the send email plugin is text only. Unless I create a email template…

It is possible to send HTML emails with the Send Email task. Refer to PReS Workflow Workflow 8.8 User Guide for more information.

Hi Phil,

I never new that and read the user guide many times without noticing the HTML portion. I made a table in Connect designer and formatted it the way I wanted, then copied the source to the email plugin, however once the email is sent the formatting is lost. This is the html source I used.

<html>
<table id="table" class="table-grid" data-column-resize="" cellpadding="0" cellspacing="0" style=" width: 100%;">
    <tbody>
        <tr>
            <td colspan="2" style="width: 50.11%;">
                SHO STAFF ANALYSIS:<br>
            </td>
            <td colspan="3" style="width: 49.89%;">
                18 October 2018<br>
            </td>
        </tr>
        <tr>
            <td colspan="5">
                <br>
            </td>
        </tr>
        <tr>
            <td style="padding: 0px;">
                <span style="font-size: 8pt;">FILENAME<br>
                </span>
            </td>
            <td style="text-align: center; padding: 0px;">
                <span style="font-size: 8pt;">TOTAL CLIENTS<br>
                </span>
            </td>
            <td style="text-align: center; width: 21mm; padding: 0px;">
                <span style="font-size: 8pt;">TOTAL PAYSLIPS<br>
                </span>
            </td>
            <td style="text-align: center; width: 21mm; padding: 0px;">
                <span style="font-size: 8pt;">TOTAL STATEMENTS<br>
                </span>
            </td>
            <td style="text-align: center; height: 4.101mm; padding: 0px;">
                <span style="font-size: 8pt;">TOTAL IMAGES<br>
                </span>
            </td>
        </tr>
        <tr>
            <td style="width: 53.8162mm;">
                <br>
            </td>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
        </tr>
        <tr>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
        </tr>
        <tr>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
        </tr>
        <tr>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
        </tr>
        <tr>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
        </tr>
        <tr>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
        </tr>
        <tr>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
        </tr>
        <tr>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
        </tr>
        <tr>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
        </tr>
        <tr>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
        </tr>
        <tr>
            <td style="border-bottom-width: 0px; border-right-width: 0px;">
                <br>
            </td>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
            <td>
                <br>
            </td>
        </tr>
    </tbody>
</table>

However the table looks like this when emailed.
screen

The black box is just to hide the client name in public forum.

Question. Is there a way for me to check the output of the email/table without spamming my emails?

Well as you just found out, HTML emails are finicky… No two email clients process them the same way and each client has its own set of restrictions and peculiarities.

At this stage, you might be better off generating an email template, since the Connect Designer has been tailored to minimize the number of potential issues with email clients. You’ll also have much better control of any future changes than if you just use a text editor.

1 Like

Yeah :sweat_smile: I basically started over with creating the table. Did the header and then the rows/cells. It is looking a lot better than my first attempt. I might explore the email template but this table will always be the same for this job.

screen

Anyways, thanks for your advice. Very much appreciated.

Regards,
S