Go to content Go to navigation Go to search

A "Macro" for Google Spreadsheets

Nov 12, 06:15 PM by Jonathan Camenisch Warning: more techie stuff.

Last night it hit me: I can make "macros" for Google docs/spreadsheets using Javascript—and simply stick them into bookmarklets. Figuring surely other people have thought of this, I Googled for "Google spreadsheet macro bookmarklet" or something along those lines and didn't turn up anything. (though people have made some pretty impressive bookmarklets for similar stuff—nothing that new about this).

So in case I ever lose it or something, here's my first Google Spreadsheet "Macro." I made it because I just needed an instant way to enter the current time into a spreadsheet. This takes more than one click now, but once I start editing a cell, I can click this bookmarklet to enter the current time:

Current Time

Lots of room for improvement, but it's a start.
  1. This is so great and useful – but how can i make this 12 hr instead of 24?

    — Drew    Aug 22, 01:31 PM    #
  2. Drew,

    I’m guessing what you want is just to change the format of the cell to 12 hr. Once you enter the time with the bookmarklet, it will be rendered in whatever format settings are applied to the cell (using the “Format” button in the spreadsheet toolbar).

    However, the formats available are pretty limited. It looks like you can do 12 hr time—as long as you don’t need to show the date with it.

    Sorry I can’t be more help than that, but it looks like we need to ask Google to give us some date+12hr options or a custom format option. I know others have asked before; maybe Google will add it some day.

    Jonathan Camenisch    Aug 22, 03:12 PM    #
  3. Thanks! I have a new question: Is there a suggested modification for the bookmarklet if I’m using the new Google browser “chrome”? I’m getting all this info even if i use the simplest formatting:

    Wed Sep 03 2008 09:23:04 GMT-0400 (Eastern Daylight Time)

    — Drew    Sep 3, 08:25 AM    #
  4. Weird, I don’t know what to say about that—especially since the formatting in Chrome works exactly the same for me as it does in Firefox. Perhaps you could try a Chrome Google group, or report the site as broken using the “Report bug or broken website” function on the page menu in Chrome.

    Jonathan Camenisch    Sep 3, 10:23 PM    #
  5. Hello ;) I’m back for help again. Looks like they’ve updated Google spreadsheets this morning with a new interface. The time stamp no longer works. do you know a way to make it work with this new interface? I have the whole office using your bookmarklet ;)

    — Drew    Oct 6, 09:49 AM    #
  6. Hello Drew,

    What exactly doesn’t work? What does it do when you use it?

    I’m afraid I can’t detect any problems. I tried on a couple of different Google Apps domains and on docs.google.com, just in case I was missing some new features.

    One difference I do notice is in the toolbar—things are moved around a lot. It took me a while to find the cell formatting button. However, once I found it, it looked like all the same options were there, and no new ones.

    Again, let me know what exactly it’s doing.

    Jonathan Camenisch    Oct 6, 07:16 PM    #
  7. Looks like i can get it to work but it’s either the time or the date, but not both like i used to have it. A separate issue is the time being 24 hr, but there might not be a way around that. thanks

    — Drew    Oct 6, 07:26 PM    #
  8. sorry, my mistake. I guess i missed the upper level menu and had gone straight to the sub menu for formatting. I guess the 24 hr thing is all thats wrong.. but not that wrong. Thanks, sorry ;)

    — Drew    Oct 6, 07:28 PM    #
  9. No problem :-)

    Jonathan Camenisch    Oct 6, 07:28 PM    #
  10. Yeh, something in the new update to google docs definitely stopped this bookmarklet from working. oh well ;0

    — Drew    Oct 30, 03:25 PM    #
  11. Here’s the solution: in the javascript replace the [1] with a [2]

    — Drew    Nov 21, 12:42 PM    #
  12. What does this do?

    Steve    Mar 17, 10:16 PM    #
  13. Steve,

    This is a bookmarklet. For a full explanation of what that means, read the Wikipedia article.

    The short explanation is this: it’s a bunch of javascript code all inserted into on link—which you can bookmark. So when you click that bookmark, it runs a little Javascript “program.”

    This concept has been used to do all sorts of powerful things. I’m using it here just to insert the current date and time into a certain spot on a certain kind of web page—namely, the active cell of a Google Spreadsheet.

    I hope that makes sense. If it doesn’t, you probably don’t need this little tool. I’m just stashing it here for myself and a few other souls who do.

    Jonathan Camenisch    Mar 21, 01:42 PM    #
  14. Nice, thanks! I don’t know why Google docs doesn’t already have a formula for this – before I was using =now() and then copying and pasting the text back into the cell. lame.

    Also, I’m sure you all could figure this out, but here is a version with seconds.

    javascript:thetime=new%20Date();document.getElementsByTagName(‘textarea’)[1].value=(thetime.getMonth()+1)+’/’thetime.getDate()’/’thetime.getFullYear()’%20’thetime.getHours()’:’thetime.getMinutes()’:’+thetime.getSeconds();void(0)

    thinksketchdesign    Nov 23, 11:43 AM    #
  15. Thanks for the addition.

    Jonathan Camenisch    Nov 23, 09:09 PM    #
Name
Email
http://
Message
  Textile Help

Jon Udell’s advice for the rest of us More on Social Networks