How do I run macros when document is created automatically? RRS feed

  • Question

  • Hi,

    So I currently have a flow that creates a .docm file inside a SharePoint document library, I need to create it as a .docm because I have 3 macros that need to be executed. Number 1 to format the text inside, number 2 to insert a picture from an online url, and number 3 to send the document as an email in the .pdf or .docx format(because there are security issues with sending .docm).

    As of now, I have set the macros to the Open() function for the document, this isn't really viable because its not completely automatic, and I have to login into SharePoint and click on the file to open it.

    Is there anyway I can have the macros run as soon as the document is created? I have tried the New() function but it doesn't seem to work, the text isn't formatted and there is no inserted picture.

    Thank you.

    Sunday, February 25, 2018 10:28 AM

All replies

  • I don't use this method.  I create all docs as docx.  The technique I use is to create a dotm addin.  The addin creates the doc and performs all the data insertion and formatting.  The document has no code.  If the user wants to do additional formatting they can load the addin, select the document and perform additional formatting.  If I need to change things I change 1 addin not 1000's of existing documents.

    I can automate the doc creation by using AutoExec.  It runs when the addin starts.  I look for a text file that tells the addin what to do.  It performs the required doc creation and deletes text file.  I've used this technique  I can call the addin from almost any language (C#, PHP...) or even a batch file.  I created an automated process that runs at 6AM every Monday, creates a document, saves it as PDF and emails it.

    Sunday, February 25, 2018 1:18 PM
  • Thanks for the quick reply! I will have a look at that today and see what I can do.
    Monday, February 26, 2018 8:45 AM
  • Hello,

    How do you create the word files? By your own executable?

    If so, following might help:

    Monday, February 26, 2018 10:21 AM
  • So I had a look at add ins, as far as I understand the add in exists on my local machine? Because this won't work as the document is created and saved inside a Document Library on SharePoint Online.


    • Edited by t3ch21 Monday, February 26, 2018 11:16 AM
    Monday, February 26, 2018 11:13 AM
  • Hello,

    How do you create the word files? By your own executable?

    If so, following might help:

    I created a custom content type in SharePoint, assigned a word document I created to act as the template (this contains all the macros). Then in my Flow, it creates a word document based off that custom content type.

    Tried using Application.Run, didn't seem to work.

    Anybody have any ideas?

    • Edited by t3ch21 Monday, February 26, 2018 4:25 PM
    Monday, February 26, 2018 4:23 PM