+ Reply to Thread
Results 1 to 12 of 12

Translate VB Code into Office Script

  1. #1
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    91,040

    Translate VB Code into Office Script

    I have a tiny code snippet that allows me to click a button, select a range and convert it to values:

    Please Login or Register  to view this content.
    I understand that it's now possible to create a button for an Office Script, so I'm wondering if anyone would know:

    1. how to translate this code to an Office Script?
    2. how to assign it to an Office Script button (although I can probably work this bit out myself: https://support.microsoft.com/en-gb/...c94cdb625766)?

    Thanks for any insights.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    91,040

    Re: Translate VB Code into Office Script

    So I recorded a script:

    Please Login or Register  to view this content.
    I am now wondering how to make it work on the current selection isntead of a fixed one. I'll keep searching ...

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,490

    Re: Translate VB Code into Office Script

    I think you can use, for example:
    Please Login or Register  to view this content.
    That said, I have not yet had the opportunity to play around with this stuff. Only realised it was available to me a couple of days ago. Thought I needed a business subscription
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    91,040

    Re: Translate VB Code into Office Script

    It arrived in the Insider desktop version some time ago.

    I have also found this script:

    Please Login or Register  to view this content.
    It replaces values in the cirrent selection with "Yes" - I need to work out how to edit this so that it converts formulae to values.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,490

    Re: Translate VB Code into Office Script

    Maybe this ...

    Please Login or Register  to view this content.
    Last edited by TMS; 06-16-2024 at 07:57 PM.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,490

    Re: Translate VB Code into Office Script

    If I have understood correctly, you cannot share scripts with a Personal Account, nor can you create script buttons.

    You can add Office Scripts to the QAT. You still need to access All Scripts and then select your Paste Values script and run it.

    Lots to learn.

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,490

    Re: Translate VB Code into Office Script

    Your code for setting a selected range to "Yes" is a little dangerous (as I discovered).

    Your code selects Sheet1 so, regardless of which sheet you have selected, Sheet1 will be selected anda cell, or cells, could be corrupted (if Sheet1 exists).

    Please Login or Register  to view this content.

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    91,040

    Re: Translate VB Code into Office Script

    Maybe this ...
    I'd worked out the first two sections - thanks, I'll give it a go.

    ... nor can you create script buttons.
    So it would seem - an oversight on MS' part, I feel - I've submitted feedback.

    Your code for setting a selected range to "Yes" is a little dangerous (as I discovered).
    Same, and I wasn't proposing using it as it stood, merely as a template. I found that one online, too.

    You still need to access All Scripts and then select your Paste Values script and run it.
    Yes - without the ability to add a button, it's a bit of a waste of time, however I suspect that will be added down the line. Still a useful learning exercise, though.

    Thanks for having a play - I'll report back later.

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    91,040

    Re: Translate VB Code into Office Script

    Yes, that does it - thank you.

    I just need to find out now how to add the script to the selection available in the Automate ribbon - not sure it's currently possible.

    Thank you!

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,490

    Re: Translate VB Code into Office Script

    You're welcome. Thanks for the rep.

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,490

    Re: Translate VB Code into Office Script

    Forgot to say, thanks for the question. I struggle to learn and apply stuff without a challenge. I now know a lot more about Office Scripts than I did.

    Can't see me ever using it personally. And, to be honest, I’m not sure who will use it IRL. IMO, it's not as easy to record, edit and adapt as VBA. And the interface is a bit clunky.

    The examples I have seen so far aren't necessarily that intuitive and, ideally, you need to be (or get) familiar with JavaScript. Having a programming background might help, but how many of us have that?

    Anyway, looks like hours of fun! Thanks again.

  12. #12
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    91,040

    Re: Translate VB Code into Office Script

    The issue is that VB Script is being deprecated at some point down the line, and we already have a situation were VB Code won't run in the browser version or on mobile devices.

    There are many fairly simple VB routines currently assigned to workbook buttons that could be replaced by an OfficeScript assigned to a button on the worksheet - like mine - making the routine usable online and on mobile devices. So I can see it taking off if they add the button option for all users.

    I already know some JS from web design - just need to brush up on it!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Office Script (Not VBA) To Grab Username who Initiated Script?
    By Norcal1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-16-2023, 04:15 AM
  2. Office Script code to print to PDF
    By XescV in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-07-2023, 01:46 PM
  3. Office Script Open Excel
    By dw_22801 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-05-2023, 04:50 PM
  4. [SOLVED] Automate menu / office script and VBA
    By scottiex in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-29-2023, 11:32 PM
  5. Moving from Office 2003 to Office 2013 - code no longer works
    By GeorgeC47 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-27-2014, 11:20 AM
  6. [SOLVED] How do i change a VBA code complied on office 2007 Bit 32 to Office 2010 Bit 64
    By nathandavies in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-18-2014, 12:17 PM
  7. Vb Script to translate 6/10/2014 to 06102014
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-11-2014, 04:36 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1