So I'm a recent convert of Outlook+Exchange to Gmail (company forced). I approve a lot of requisitions and such in email for automated processing by other applications. To do this, I simply review the message and if I approve it, reply and add "Approved" to the end of the subject. In Outlook, I created the VBA macro that would take the selected message and do the this task automatically: reply; modify the subject; send; and move the original message. This made for 2 click process... 1 to select the message and review it, one to respond with approval and archive the original message.

I'm an old hand with VBA but completely green with google script. From what I've seen, it looks intuitive but I need some help getting started. I'd appreciate some pointers. I've included a snippet of the VBA code below:

Dim obj As Object
Dim msg As Outlook.MailItem
Dim msgReply As Outlook.MailItem

Set obj = GetCurrentItem 'grabs the currently selected item.
If TypeName(obj) = "MailItem" Then 'make sure the item is a mailitem
    Set msg = obj 'msg is now the mail item to work on
    If msg.Parent = "AP Invoices" Then 'need to make sure the msg is in the AP Invoices folder 
        Set msgReply = msg.ReplyAll 'this initiates a reply all to the msg
        msgReply.Subject = msgReply.Subject & "Approved" 'adds "Approved" to end existing subject
        msgReply.Display 'displays the message
        msgReply.Send 'sends the message
        msg.UnRead = False 'marks the original msg as read
        msg.Move olProcessedFolder 'moves the original msg to a different folder
    end if
end if

In Outlook, I used rules to get the email into the "AP Invoices" folder and I have Gmail doing the same for a label using a filter.

Question: Once I have a script, how do I manually initiate it? On Outlook, I added a command button on the toolbar that launched the VBA macro... not sure if that is possible in Gmail.

Appreciate any assistance.


By exclusively using Google Apps Script there is no way to add a custom button to the Gmail toolbar to call a script. You could create a Gmail add-on that will show a sidebar with custom button, text boxes etc.

You could create a bookmarklet, use Greasemonkey / Tampermonkey or another similar web browser extension to use a "user script" and the Google Apps Script API to execute a Google Apps Script function.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.