How to dynamically attach from OneDrive

In Shared Email Templates for Outlook

With the ~%WhatToEnter macro (~%WTE) nested within ~%Attach, you'll easily choose what file to use as an email attachment via the ~%WTE dialog when pasting your template. And the tandem of ~%WTE and ~%Attach will ensure that the file you select is attached even if the files of interest are scattered across different folders on your OneDrive.

Suppose you have discount coupons saved as PDF files in several folders on OneDrive and want to add them all to a dropdown list that will show up when you paste your template. Here's what you can do:

First of all, create a simple dataset and include full paths of your files in it. To get a file path, click the Insert Macro icon in a dataset cell.
The Insert Macro icon

In the search box on the Shared Email Templates pane, type in "attach from OneDrive" and select the corresponding option.
Select to attach from OneDrive.

Select a file that you're going to use as an attachment and copy the file path by clicking the Copy link icon.
The Copy link icon

Then click Cancel.

Paste the copied link into the corresponding cell in your dataset.
The copied link is pasted.

Repeat the same for each of the files that are going to be attached. When you're done, save your dataset.
A sample dataset with file paths

Tip. You can connect datasets from Excel files.

As soon as your dataset is ready, the tandem of ~%WTE and ~%Attach is to be added to your template.

  1. In your template, insert the ~%Attach macro selecting Attach from OneDrive and any of the files you're going to attach:
    A file to attach from OneDrive
  2. Then insert the ~%WTE macro specifying your dataset and the column with the full paths of the files to be attached:
    The ~%WTE dialog
  3. Right-click the ~%WTE macro placeholder to copy the macro text:
    Copy Macro Text to Clipboard
  4. Right-click the ~%Attach macro placeholder to start editing it:
    Edit Macro Text
  5. Delete the "fileName", "driveId", and "fileId" parameters. Then enter the "filePath" parameter instead and paste the copied ~%WTE macro text into it. Click Save:
    Nest ~%WTE.

You've just nested the ~%WTE macro within ~%Attach, and the macros are ready to do their job ;)

Don't forget to delete the ~%WTE macro placeholder you added in Step 2.

Try and paste your template to see the dialog where you can select an attachment for your email message:
Files to attach in a dropdown list

Post a comment

Seen by everyone, do not publish license keys and sensitive personal info!

If you have any questions or issues with this add-in, please feel free to post your concerns in the comments area. As soon as we answer, a notification message will be sent to your e-mail. If you do not want to share your thoughts in public, please contact us at support@ablebits.com.