VBS in a DOS batch file

Author Message
jphilippa

  • Total Posts : 3
  • Scores: 0
  • Reward points : 0
  • Joined: 10/4/2010
  • Status: offline
VBS in a DOS batch file Tuesday, October 05, 2010 1:55 AM (permalink)
0
I do not understand VBS but was given VBS code which I have used successfully in a DOS batch file. That success makes me think that maybe I can do it again in another context. I've been given code as a result of saying that I wanted to save an open Excel spread sheet by means of a DOS batch file. The code does not work by itself in the batchfile, and is so dissimilar from the first example which I mentioned, that I can get no clues from the first for applying to the second. Can someone here give me the 'missing links' to make the following code effective in a DOS batchfile ? :

Dim x
set x = getobject(, "Excel.application")
'msgbox x.caption
x.SaveAs "C:\FileLocation\WorkBookName.XLS"
x.Application.Quit
Set x= Nothing

A second suggestion was to 'capture' the macro created for/when saving the spreadsheet. That content is much simpler, but again, I don't know how to make it effective in a DOS batchfile.


 
#1
    ebgreen

    • Total Posts : 8227
    • Scores: 98
    • Reward points : 0
    • Joined: 7/12/2005
    • Status: offline
    Re:VBS in a DOS batch file Tuesday, October 05, 2010 7:37 AM (permalink)
    0
    Neither of those would be doable in a dos batch file.
    "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
    Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
    http://www.visualbasicscript.com/m_47117/tm.htm
     
    #2
      ebgreen

      • Total Posts : 8227
      • Scores: 98
      • Reward points : 0
      • Joined: 7/12/2005
      • Status: offline
      Re:VBS in a DOS batch file Tuesday, October 05, 2010 7:39 AM (permalink)
      0
      The closest that you might be able to get would be to put a macro in the workbook that would print the sheet you want then close excel. Then it would be possible to call the excel file and pass in a command line parameter that caused it to run that macro.
      "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
      Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
      http://www.visualbasicscript.com/m_47117/tm.htm
       
      #3
        jphilippa

        • Total Posts : 3
        • Scores: 0
        • Reward points : 0
        • Joined: 10/4/2010
        • Status: offline
        Re:VBS in a DOS batch file Tuesday, October 05, 2010 10:31 AM (permalink)
        0
        I don't want a sheet printed - I just want to save the opened and edited  excel sheet.
         
        #4
          ebgreen

          • Total Posts : 8227
          • Scores: 98
          • Reward points : 0
          • Joined: 7/12/2005
          • Status: offline
          Re:VBS in a DOS batch file Tuesday, October 05, 2010 11:56 PM (permalink)
          0
          Sorry, that isn't possible in DOS. To do that you would need to use the COM API that Excel exposes and DOS has no way to access that. Why not just write a VBScript and have your batch file call that?
          "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
          Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
          http://www.visualbasicscript.com/m_47117/tm.htm
           
          #5
            jphilippa

            • Total Posts : 3
            • Scores: 0
            • Reward points : 0
            • Joined: 10/4/2010
            • Status: offline
            Re:VBS in a DOS batch file Wednesday, October 06, 2010 12:51 AM (permalink)
            0
            That is precisely what I have done, with much assistance from an Excel forum
            and it works. I had many vicissitudes in the excel forum and it seemed maybe I was asking the wrong people - that is when I sought and found this forum. But then my fortunes took a turn for the better, and someone at MrExcel took me through the process step by step. Presto, DONE. Thank you.
             
            #6

              Online Bookmarks Sharing: Share/Bookmark

              Jump to:

              Current active users

              There are 0 members and 1 guests.

              Icon Legend and Permission

              • New Messages
              • No New Messages
              • Hot Topic w/ New Messages
              • Hot Topic w/o New Messages
              • Locked w/ New Messages
              • Locked w/o New Messages
              • Read Message
              • Post New Thread
              • Reply to message
              • Post New Poll
              • Submit Vote
              • Post reward post
              • Delete my own posts
              • Delete my own threads
              • Rate post

              2000-2012 ASPPlayground.NET Forum Version 3.9