+ Reply to Thread
Results 1 to 8 of 8

Excel macro to VBS script

  1. #1
    Forum Contributor
    Join Date
    02-16-2006
    MS-Off Ver
    OFFICE 365
    Posts
    244

    Excel macro to VBS script

    I have the following code that works great inside my excel workbook. However, the spreadsheet where this script resides is about to be converted into a shared workbook and I will be unable to use macros in it. I was looking at using a stand-alone script outside excel to modify the workbook but I have run into issues.

    Following is the code I have in excel:

    Please Login or Register  to view this content.
    This is my start but I keep runnin into issues:

    Please Login or Register  to view this content.
    Any help/advise would be appreciated.


    Thanks,

    Met

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Excel macro to VBS script

    Hi Metrazal,

    When in situations like yours, I have had problems in the past with Excel trying to identify which workbook and which sheet is being referenced, especially when using the .Cells syntax. I have had problems with .Cells (I'm not sure if the problems are real or imaginary) when using the 'with Sheets' construction that you are using.

    My first inclination would be to explicitly reference these items like in the untested sample code below:
    Please Login or Register  to view this content.
    I wouldn't remove the 'with Sheets', I'd just add the explicit references.

    Lewis

  3. #3
    Forum Contributor
    Join Date
    02-16-2006
    MS-Off Ver
    OFFICE 365
    Posts
    244

    Re: Excel macro to VBS script

    LJ, Thanks for the advice. I have tried playing around with your suggestion but to no avail. There are probably multiple issues with the script but the first error occurs at line 5.

    Thanks,
    Met

  4. #4
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Excel macro to VBS script

    There I go again. I did the same thing yesterday. You're talking VBS and I'm thinking VBA from an Independent workbook.

    Is it possible for you to use the 'shared workbook' as an Excel Data file, by putting all your code in a Master workbook, and just reading (and possibly writing) to the 'shared workbook' (if Microsoft allows either).

    Your original code might work with the modifications I originally suggested.

    Lewis

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Excel macro to VBS script

    In VBS, all variables are Variants:

    Dim objExcel, objWorkbook, ...

    Anything from the Excel library has to be qualified by the application variable: objExcel.Union
    Entia non sunt multiplicanda sine necessitate

  6. #6
    Forum Contributor
    Join Date
    02-16-2006
    MS-Off Ver
    OFFICE 365
    Posts
    244

    Re: Excel macro to VBS script

    LJ, Thanks again. I think you are correct in that I can run the script as is in Excel regardless of whether or not the workbook is shared. (I just cannot modify it while it is shared.)

    However, It may be cleaner if I run this as a VBS script because I am debating about excuting the script through Scheduler.

    I am going to play around with shg's suggestion and see if I can get the vbs scipt to work. (It may be a better option.)

    Thanks to all..

    Met

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Excel macro to VBS script

    Quote Originally Posted by Metrazal View Post
    It may be cleaner if I run this as a VBS script because I am debating about excuting the script through Scheduler.
    You can schedule a workbook to run from Task Scheduler.

    Trying to debug code without a development environment is difficult.

  8. #8
    Forum Contributor
    Join Date
    02-16-2006
    MS-Off Ver
    OFFICE 365
    Posts
    244

    Re: Excel macro to VBS script

    Thanks to everyone for the help. I decided to, as suggested, run the script inside excel and schedule the task from there.

    Thanks again,

    Met

+ 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. script to run the macro from Vb script with out opening the excel file
    By chandanp in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-27-2021, 03:33 AM
  2. need script for excel macro
    By vimalanathk in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-23-2012, 06:02 AM
  3. Create VBA script to short, dedicated button in excel for script?
    By realized in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-01-2009, 11:54 PM
  4. Excel Macro or other script
    By MartinaL in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-06-2005, 09:05 PM
  5. Excel Macro using vb script
    By Lillian in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-07-2005, 02:06 AM

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