+ Reply to Thread
Results 1 to 19 of 19

Convert some working VBA code to work in VBScript [Test File State]

  1. #1
    Forum Contributor dlow's Avatar
    Join Date
    08-12-2013
    Location
    EveryWhere
    MS-Off Ver
    Excel 2007, 2010
    Posts
    275

    Convert some working VBA code to work in VBScript [Test File State]

    Hi,

    I am trying to convert some working VBA code to work in VBScript.
    The error I am getting is: "VBScript compilation error: Expected end of statement" on the line of code with the Red font.
    Please Login or Register  to view this content.
    TIA
    Last edited by dlow; 11-28-2015 at 01:45 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Convert some working VBA code to work in VBScript [Test File State]

    Hello dlow,

    Try this statement...

    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor dlow's Avatar
    Join Date
    08-12-2013
    Location
    EveryWhere
    MS-Off Ver
    Excel 2007, 2010
    Posts
    275

    Re: Convert some working VBA code to work in VBScript [Test File State]

    Hi Leith,

    Thanks for the reply sadly, I still get the same error: "VBScript compilation error: Expected end of statement"

  4. #4
    Forum Contributor dlow's Avatar
    Join Date
    08-12-2013
    Location
    EveryWhere
    MS-Off Ver
    Excel 2007, 2010
    Posts
    275

    Re: Convert some working VBA code to work in VBScript [Test File State]

    Heres my full codeModule

    Please Login or Register  to view this content.
    Apologizes for the mess I still have to clean the code up.
    Oh, I am debugging or testing the code in PrimalScript
    Last edited by dlow; 11-28-2015 at 03:04 PM.

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Convert some working VBA code to work in VBScript [Test File State]

    I don't think you can use the VBA file I/O methods in VBS, I think you'll need to use the File System Object.
    If posting code please use code tags, see here.

  6. #6
    Forum Contributor dlow's Avatar
    Join Date
    08-12-2013
    Location
    EveryWhere
    MS-Off Ver
    Excel 2007, 2010
    Posts
    275

    Re: Convert some working VBA code to work in VBScript [Test File State]

    Ok thanks I will give that a try.

    Thanks Norie.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Convert some working VBA code to work in VBScript [Test File State]

    Try this, which is adapted from some other code and, unfortunately, untested.
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor dlow's Avatar
    Join Date
    08-12-2013
    Location
    EveryWhere
    MS-Off Ver
    Excel 2007, 2010
    Posts
    275

    Re: Convert some working VBA code to work in VBScript [Test File State]

    Thanks

    The code you provided works in VBA & no errors in VBS, but its not opening the file in VBS, but does in VBA.

    Sorry for the late reply. [Had to run an errand & I just got back].

    Gonna step through & see if I can find the problem with this code running in VBScript.

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Convert some working VBA code to work in VBScript [Test File State]

    What is the code meant to do?

    Have you checked file paths and names?

  10. #10
    Forum Contributor dlow's Avatar
    Join Date
    08-12-2013
    Location
    EveryWhere
    MS-Off Ver
    Excel 2007, 2010
    Posts
    275

    Re: Convert some working VBA code to work in VBScript [Test File State]

    Yikes my script wasnt even firing, beacuse when I added:
    Please Login or Register  to view this content.
    to the top of my code & nothing happened.

    I removed the Sub & End Sub; the Exits also. Now its firing & Ive got some new errors to fix.

    But what I am lost on is why dont I need Sub? Is it that VBS is not modular & we just wouldnt have many Subroutines in a Script.

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Convert some working VBA code to work in VBScript [Test File State]

    VBS does use Sub(s) and Function(s).

    How are you trying to run the code?

  12. #12
    Forum Contributor dlow's Avatar
    Join Date
    08-12-2013
    Location
    EveryWhere
    MS-Off Ver
    Excel 2007, 2010
    Posts
    275

    Re: Convert some working VBA code to work in VBScript [Test File State]

    Hi Norie

    Didnt see your reply #9
    What is the code meant to do?
    I have a large file that I want to make sure is open. Because its a large file I am planning to Script it so the task can be ran but the code doesnt wait for the file to open.
    While that file is opening if it needs to be opend I would also be running some code that runs about 15 minutes. So if the code doesnt have to wait on the file it all gets done a little faster.

    Have you checked file paths and names?
    Yeah the path are correct.
    It wasnt firing because I had Sub/EndSub & Exit in the Script.

    Do you know why Script doesnt need Sub/EndSub?
    I can always Google search it if its to much trouble to answer/type in a post.
    Last edited by dlow; 11-28-2015 at 06:22 PM.

  13. #13
    Forum Contributor dlow's Avatar
    Join Date
    08-12-2013
    Location
    EveryWhere
    MS-Off Ver
    Excel 2007, 2010
    Posts
    275

    Re: Convert some working VBA code to work in VBScript [Test File State]

    Ah,

    I am running it from PrimalScript

  14. #14
    Forum Contributor dlow's Avatar
    Join Date
    08-12-2013
    Location
    EveryWhere
    MS-Off Ver
    Excel 2007, 2010
    Posts
    275

    Re: Convert some working VBA code to work in VBScript [Test File State]

    Ok so its working now but Im getting errors on WindowState Property I changed the font to Red on those line.

    Please Login or Register  to view this content.

  15. #15
    Forum Contributor dlow's Avatar
    Join Date
    08-12-2013
    Location
    EveryWhere
    MS-Off Ver
    Excel 2007, 2010
    Posts
    275

    Re: Convert some working VBA code to work in VBScript [Test File State]

    The 1st & 2nd error thrown is: Microsoft Excel: Unable to set the WindowState property of the Application class

    So I added:
    Please Login or Register  to view this content.
    to the top of the code, & changed the code accordingly but I still get an error shown in Red below.
    Please Login or Register  to view this content.

  16. #16
    Forum Contributor dlow's Avatar
    Join Date
    08-12-2013
    Location
    EveryWhere
    MS-Off Ver
    Excel 2007, 2010
    Posts
    275

    Re: Convert some working VBA code to work in VBScript [Test File State]

    Changed the constants to:
    Please Login or Register  to view this content.
    As per the MSDN

    The code works & runs to the end if I use vbMaximized but if I use vbNormal it gets hung where I try to use it.

    Does anyone have any idea how I could fix the error in Red?

    Please Login or Register  to view this content.

  17. #17
    Forum Contributor dlow's Avatar
    Join Date
    08-12-2013
    Location
    EveryWhere
    MS-Off Ver
    Excel 2007, 2010
    Posts
    275

    Re: Convert some working VBA code to work in VBScript [Test File State]

    Yet again I bumbled my way though it.

    Try this:
    Please Login or Register  to view this content.
    Thanks everybody for your help.

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

    Re: Convert some working VBA code to work in VBScript [Test File State]

    Quote Originally Posted by dlow View Post
    Yet again I bumbled my way though it.

    Try this:
    Please Login or Register  to view this content.
    Thanks everybody for your help.
    You can get the value of constants in the Object Browser, or just in the Immediate window:

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  19. #19
    Forum Contributor dlow's Avatar
    Join Date
    08-12-2013
    Location
    EveryWhere
    MS-Off Ver
    Excel 2007, 2010
    Posts
    275

    Re: Convert some working VBA code to work in VBScript [Test File State]

    No way! lol....
    Thanks a lot Shg, Youre the Man

+ 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. Convert VBA Code to work as a Macro
    By nwb in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-08-2015, 01:01 PM
  2. [SOLVED] Cant make inputbox work in working code
    By abjac in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-15-2014, 04:47 PM
  3. [SOLVED] Inputbox in working code dont work
    By abjac in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-13-2014, 03:06 AM
  4. [SOLVED] Work Order tracker date code not working properly
    By Jeff up North in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 02-15-2013, 03:25 PM
  5. Code to work out working days a task took
    By ianma in forum Excel General
    Replies: 1
    Last Post: 10-21-2009, 10:44 AM
  6. Using a vbscript HTML file to work with Excel
    By cpenticuff in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-17-2009, 04:00 PM
  7. .SpecialCells(xlLastCell).Select does not work in vbscript
    By ckb in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-18-2007, 12:58 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