Consulting

Results 1 to 5 of 5

Thread: How do I set up Visual Studio to debug .vbs and/or .wsf scripts?

  1. #1
    VBAX Regular
    Joined
    Apr 2007
    Location
    Sector ZZ 9 Plural Z Alpha
    Posts
    6
    Location

    How do I set up Visual Studio to debug .vbs and/or .wsf scripts?

    How do I setup Visual Studio (2005) to give me the same debugging features as the Excel/Word/Outlook VBA editors?

    My job for the next few months is to create and maintain .vbs and .wsf scripts that drive MS Office applications. (e.g. a scheduled script that opens a series of Office documents, runs embedded vba functions, and do some other stuff)

    When programming in Excel or whatever, I can test functions, set breakpopints, use the "Immediate" window, etc....

    I would really like to step through scripts and check variables in these driver scripts but can't figure out how to make it happen. So I have to edit the script, save, then run the script manually via start->run or on the commandline.

    How do I set up Visual Studio to allow the same debugging features?



    I'm runinng VS2005 on Windows 2k, interacting with Office 2k and IE 6.

  2. #2
    Knowledge Base Approver
    The King of Overkill!
    VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Sukotto,

    When I need to debug a .vbs script, I copy the whole thing to a standard module in vba (with the exception of a couple vbscripts that use classes), put all the Dim statements at the top, and usually enclose the main code in a sub called "SubMain" or something similar, and keep the Dim statements out of it (so they'll be public variables). Any separate subs/functions will still be separate, and then run/stepthrough SubMain as needed. I've never
    used .wsf scripts so I can't say for sure about those, but for my VBS files it works great. Sometimes I'll write them in vba using the same idea, then just copy/paste into notepad (though usually i just write them there). Using the VBE makes the vbscript nicer looking too, since it capitalizes/formats it.

    Matt

  3. #3
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Just as a quick/simple example of what im referring to, if my vbs file looks like:
    dim i, Cntr
    cntr=1
    for i = 1 to 10
     doubleavariable cntr
    next
    msgbox cntr
    
    function DoubleAVariable(aVar)
     avar=2*avar
    end function
    In VBA it would look like:[vba]Dim i, Cntr
    Sub SubMain()
    Cntr = 1
    For i = 1 To 10
    DoubleAVariable Cntr
    Next
    MsgBox Cntr
    End Sub

    Function DoubleAVariable(aVar)
    aVar = 2 * aVar
    End Function[/vba]

  4. #4
    VBAX Regular
    Joined
    Apr 2007
    Location
    Sector ZZ 9 Plural Z Alpha
    Posts
    6
    Location
    What editor are you talking about here? There does not seem to be a "VBA
    " File/Project type in Visual Studio 2005.

  5. #5
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    My apologies, I was actually referring to the Visual Basic for Applications VBE that comes with office (excel VBA, word VBA, etc)

    I don't have VS2005 here at work so I can't say for sure, but any VB-based project should work. I havent looked at vs2005 in a while though so I could be thinking of an earlier version (I usually use vb6's visual studio).

Posting Permissions

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