I'm new to VBS and programming in general and in order to get a good
start on scripting I am looking for a good editor with highlighting and
code-completion. Ideally there would be a sidebar with all the commands
and some reference to what they do. I'd also like a syntax-checker that
prevents the most stupid typos and other simple syntax mistakes.
... and there's more. Since I'm going to script for a particular
application, I'd like to add the the list of application specific
methods to the highlighter and code-completion.
Am I asking for too much?
Is there something like Visual Studio for VBS?
Simon.
Hi,
I am using Excel-VBE to edit VBS by the following script.
You can use Object Browser to know refferenced application's objects,
properties, methods.
On Excel2002 or later, you must change macro security option.
If you run the script by doubleclicking, the script regists itself to vbs file's
context menu.
' FileName : VBSEdit.vbs
Option Explicit
Dim Args, xlApp, iFile, Buf, FS, oFile
Set Args = WScript.Arguments
If Args.Count = 0 Then Reg_UnReg ' Set/Reset Context Menu
If Args.Count <> 1 Then WScript.Quit
If LCase(Right(Args(0), 4)) <> ".vbs" Then WScript.Quit
Set xlApp = CreateObject("Excel.Application")
xlApp.Workbooks.Add().ActiveSheet.Name = "Dummy"
With xlApp.VBE
On Error Resume Next
With .ActiveVBProject.References
'Reference for Scripting Runtime
.AddFromGuid "{420B2830-E718-11CF-893D-00A0C9054228}", 0, 0
'Reference for Shell Controls And Automation
.AddFromGuid "{50A7E9B0-70EF-11D1-B75A-00A0C90564FE}", 0, 0
'Reference for VBScript Regular Expressions
.AddFromGuid "{3F4DACA7-160D-11D2-A8E9-00104B365C9F}", 0, 0
'Reference for WMI Scripting
.AddFromGuid "{565783C6-CB41-11D1-8B02-00600806D9B6}", 0, 0
'Reference for Windows Script Host
.AddFromGuid "{F935DC20-1CF0-11D0-ADB9-00C04FD58A0B}", 0, 0
'Reference for WSHController
.AddFromGuid "{563DC060-B09A-11D2-A24D-00104BD35090}", 0, 0
End With
On Error GoTo 0
.MainWindow.Visible = True
.ActiveVBProject.VBComponents.Add 1
.CodePanes(1).Window.SetFocus
iFile = Args(0)
With .CodePanes(1).CodeModule
.DeleteLines 1, .CountOfLines: .AddFromFile iFile
End With
Do While .MainWindow.Visible: WScript.Sleep 1000: Loop
With .CodePanes(1).CodeModule
Buf = .Lines(1, .CountOfLines)
End With
End With
xlApp.ActiveWorkbook.Close False: xlApp.Quit: Set xlApp = Nothing
oFile = InputBox("Input File Name", , LongName(iFile))
If oFile = "" Then WScript.Quit
If InStr(oFile, ".") = 0 Then oFile = oFile & ".vbs"
Set FS = CreateObject("Scripting.FileSystemObject")
If FS.FileExists(oFile) Then
If MsgBox("The same name file exists. Do you overwrite it ?", _
vbYesNo) = vbNo Then Set FS = Nothing: WScript.Quit
End If
Set oFile = FS.CreateTextFile(oFile)
oFile.Write Buf: oFile.Close
'
Sub Reg_UnReg()
Const TKey = "HKCR\VBSFile\shell\EditInVBE\": Dim ENo
With CreateObject("WScript.Shell")
On Error Resume Next
.RegRead TKey: ENo = Err.Number
On Error GoTo 0
If ENo <> 0 Then
.RegWrite TKey, "Edit in VBE(&V)"
.RegWrite TKey & "Command\", _
"wscript """ & WScript.ScriptFullName & """ ""%L"""
.Popup "Registry setting added", 1
Else
.RegDelete TKey & "Command\": .RegDelete TKey
.Popup "Registry setting removed", 1
End If
End With
End Sub
Function LongName(ShortName)
With CreateObject("WScript.Shell")
With .CreateShortcut("dummy.lnk")
.TargetPath = ShortName: LongName = .TargetPath
End with
End with
End Function
--
Miyahn (Masataka Miyashita) JPN
Microsoft MVP for Microsoft Office - Excel(Jan 2005 - Dec 2005)
HQF0...@nifty.ne.jp
I want to use VBS for scripting a 3D CAD program (Rhinoceros), are you
sure Excel-VBE is what I am looking for?
I don't know that CAD program, so I'm not sure.
Add the referense to the type-library of that program.
If you want IntelliSense support, use early binding.
(After editing, change the binding to late binding.)
Using Excel-VBE, I can edit the script controling Lotus Notes, Ichitaro(Japanese
famous word processing program), Internet Explorer, etc.
re: intellisense support in VBA for coding VBScript-WSH
As long as you use strong typing, it's still OK to use
CreateObject(); then, all that has to be commented out is the
strong typing.
' begin VBA
' declare interfaces as strong types
Dim WSHShell As WSHShell
Dim WScript As IHost_Class
Dim RegExp As RegExp
Dim Match As Match
Dim oIE As InternetExplorer
Dim colMatch As MatchCollection
Dim oFSO As FileSystemObject
Sub main()
Dim lResult
Dim sOut
Dim vArr' etc
' illegal in VBScript-WSH, but a must here for sensing
Set WScript = New IHost_Class
Set RegExp = New RegExp ' OK in WSH
Set WSHShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set colMatch = RegExp.Execute(sOut)
Set oIE = CreateObject("InternetExplorer.Application")
' etc
end Sub
' end VBA
regards,
tlviewer
I see.
>
> ' begin VBA
>
> ' declare interfaces as strong types
> Dim WSHShell As WSHShell
> Dim WScript As IHost_Class
> Dim RegExp As RegExp
> Dim Match As Match
> Dim oIE As InternetExplorer
> Dim colMatch As MatchCollection
> Dim oFSO As FileSystemObject
>
> Sub main()
> Dim lResult
> Dim sOut
> Dim vArr' etc
> ' illegal in VBScript-WSH, but a must here for sensing
> Set WScript = New IHost_Class
I quite forgot this class.
I'll add the reference to 'Windows Script Host' in my script like this.
With xlApp.VBE
On Error Resume Next
With .ActiveVBProject.References
'Reference for Windows Script Host
.AddFromGuid "{60254CA0-953B-11CF-8C96-00AA00B8708C}", 0, 0
Thanks.
Sorry, you lost me.
I'm looking for a simple editor which will help me to *learn* VBS.
Simon.
Excel-VBE is simpler than Visual Studio and (I think) It's Object Browser,
IntelliSense will help you to learn VBS.
Do you have any Office 2000/XP/2003 apps?
To install the optional Microsoft Script Editor
--> Add/Remove programs, <your Office 2000/XP app>
--> change, add or remove features
then look under Office Tools -> HTML Source Editing -> Web Scripting.
With the Office XP (and later) version of MSE (MSE7.EXE), syntax coloring
and IntelliSense both work great right out of the box. It already knows
about js/vbs/wsf script extensions (I had to add the wsc extension
manually).
You can also pass a file name via the command line when you start MSE7.EXE
and it will open the script in the editor (the mse.exe Office 2000 version
wouldn't accept a file name via the command line).
You can't start the debugger for WSH hosted script files via the Debug /
Start menu. But there is a 'View/Open With...' menu option. The Open With
dialog already had wscript.exe as an option.
You can add more 'View/Open With...' choices for:
wscript.exe //d --> which I named wscript (debug enabled)
wscript.exe //x --> which I named wscript (start in debugger)
and cscript.exe versions as well. The dialog complains (only a bit,
probably because of the switches) but lets you add them anyway.
What's really nice is that when you use these, you get a choice of debugging
in the current instance of MSE (where you're editing) or a new instance of
MSE or in any other available script debugger you may also have installed,
such as the various versions of VStudio.
--
Michael Harris
Microsoft MVP Scripting
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Please ask follow-up questions via the original newsgroup thread.
I didn't know that MS script editor existed before, but by seeing this post
it got my curiosity.
- You said you use Lotus notes objects, ie, etc. How can I add those and
others?
- How do I use early binding or late binding to call intellisense?
Thanks
RT
"Miyahn" <HQF0...@nifty.ne.jp> wrote in message
news:%23UTvyKR...@tk2msftngp13.phx.gbl...
RT
"Rafael T" <okina...@hotmail.com> wrote in message
news:uFmeCojP...@TK2MSFTNGP12.phx.gbl...
I have Word 2002 which came with Works, but no Office as such.
> To install the optional Microsoft Script Editor
> --> Add/Remove programs, <your Office 2000/XP app>
> --> change, add or remove features
There doesn't appear to be this option. Maybe Word from the Works suite
is different to Word from the Office suite.
If I really need Office to get MSE, then I guess I could buy the
educational version, since I'm a student. But if I have to spend money
anyway I could just as well buy Visual Studio if that is any help at all
with VBS ...
Simon.
Here is 'VBSEdit.vbs' for Word.
' FileName:VBSEdit.vbs
Option Explicit
Dim Args, wdApp, iFile, Buf, FS, oFile
Set Args = WScript.Arguments
If Args.Count = 0 Then Reg_UnReg ' Set/Reset Context Menu
If Args.Count <> 1 Then WScript.Quit
If LCase(Right(Args(0), 4)) <> ".vbs" Then WScript.Quit
Set wdApp = CreateObject("Word.Application")
wdApp.Documents.Add()
With wdApp.VBE
On Error Resume Next
With .VBProjects(.VBProjects.Count - 1).References
'Reference for Windows Script Host
.AddFromGuid "{60254CA0-953B-11CF-8C96-00AA00B8708C}", 0, 0
'Reference for Scripting Runtime
.AddFromGuid "{420B2830-E718-11CF-893D-00A0C9054228}", 0, 0
'Reference for Shell Controls And Automation
.AddFromGuid "{50A7E9B0-70EF-11D1-B75A-00A0C90564FE}", 0, 0
'Reference for VBScript Regular Expressions
.AddFromGuid "{3F4DACA7-160D-11D2-A8E9-00104B365C9F}", 0, 0
'Reference for WMI Scripting
.AddFromGuid "{565783C6-CB41-11D1-8B02-00600806D9B6}", 0, 0
'Reference for Windows Script Host Object Model
.AddFromGuid "{F935DC20-1CF0-11D0-ADB9-00C04FD58A0B}", 0, 0
'Reference for WSHController
.AddFromGuid "{563DC060-B09A-11D2-A24D-00104BD35090}", 0, 0
End With
On Error GoTo 0
.MainWindow.Visible = True
.VBProjects(.VBProjects.Count - 1).VBComponents.Add 1
.CodePanes(1).Window.SetFocus
iFile = Args(0)
With .CodePanes(1).CodeModule
.DeleteLines 1, .CountOfLines: .AddFromFile iFile
End With
Do While .MainWindow.Visible: WScript.Sleep 1000: Loop
With .CodePanes(1).CodeModule
Buf = .Lines(1, .CountOfLines)
End With
End With
wdApp.ActiveDocument.Close False
wdApp.Quit: Set wdApp = Nothing
oFile = InputBox("Input File Name", , LongName(iFile))
If oFile = "" Then WScript.Quit
If InStr(oFile, ".") = 0 Then oFile = oFile & ".vbs"
Set FS = CreateObject("Scripting.FileSystemObject")
If FS.FileExists(oFile) Then
If MsgBox("The same name file exists. Do you overwrite it ?", _
vbYesNo) = vbNo Then Set FS = Nothing: WScript.Quit
End If
Set oFile = FS.CreateTextFile(oFile)
oFile.Write Buf: oFile.Close
WScript.Quit
'
Sub Reg_UnReg()
Const TKey = "HKCR\VBSFile\shell\EditInVBE\": Dim ENo
With CreateObject("WScript.Shell")
On Error Resume Next
.RegRead TKey: ENo = Err.Number
On Error GoTo 0
If ENo <> 0 Then
.RegWrite TKey, "Edit in VBE(&V)"
.RegWrite TKey & "Command\", _
"wscript """ & WScript.ScriptFullName & """ ""%L"""
.Popup "Registry setting added", 1
Else
.RegDelete TKey & "Command\": .RegDelete TKey
.Popup "Registry setting removed", 1
End If
End With
End Sub
Function LongName(ShortName)
With CreateObject("WScript.Shell")
With .CreateShortcut("dummy.lnk")
.TargetPath = ShortName: LongName = .TargetPath
End with
End with
End Function
--
You can't add the references on MSE(MS script editor).
You can add the references for various type-libraries on VBE.
Try my script and select 'Tools'->'References' on VBE menu.
(I'm not sure English menu expression)
Open Object Browser(F2), select library, take a look classes and
members list box.
To add the references by code, change my script as the following.
---
With xlApp.VBE
On Error Resume Next
With .ActiveVBProject.References
'Reference for Microsoft Internet Controls
.AddFromGuid "{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}",0, 0
'Reference for Lotus Notes Automation Classes
.AddFromGuid "{1CF542E0-D988-11CF-B485-00805F98FACE}", 0, 0
---
> - How do I use early binding or late binding to call intellisense?
To use early binding, declare object variables using 'As' clause.
Note:
VBS does not support 'As' clause, so you must remove that
before execution.
'As' clauses are only for editing.
To use late binding, declare object variables without 'As' clause.
(or do not declare.)
Sample sub procedure, 'As' clauses are commented out.
Sub Test()
Dim IE 'As InternetExplorer
Dim nSS 'As NOTESSESSION
Dim nDb 'As NOTESDATABASE
Set IE = CreateObject("Internetexplorer.Application")
IE.VISIBLE = True
IE.NAVIGATE "About:Blank"
Set nSS = CreateObject("NOTES.NOTESSESSION")
Set nDb = nSS.CURRENTDATABASE
MsgBox nDb.FILENAME
Set nDb = Nothing: Set nSS = Nothing: Set IE = Nothing
End Sub
I should qualify my recommendation by
saying that I am also the author. I avoid
answering this kind of "which editor" question
in general because it doesn't seem proper
to use the newsgroup as an advertising venue.
But in this case WEB-ED is almost exactly
what you've requested.:
_____________________________
* highlighting -
Yes.
* code-completion -
Yes. ("intellisense"-style)
* sidebar with all the commands
and some reference to what they do. -
No, but info. appears
in status bar when a method is used.
* syntax-checker that prevents the most stupid typos
and other simple syntax mistakes. -
Yes, that's included.
* to add the the list of application specific
methods to the highlighter and code-completion. -
Yes. Any object can be added for "intellisense"-style
popup code-completion menus.
Joe Priestley
mayayX...@mindYYspring.com
For return email remove XX and YY.
Thank you Miyahn,
unfortunately I get an error when trying to open a *.vbs file with "Edit
with VBSEdit" error code: 800A17B4, message: something like "Access
denied to untrusted Visual Basic Project"
Could that have something to do with having changed the security level
for the local zone in IE?
Simon.
No.
You must change Word's Macro Security Option at your own risk.
'Tools' -> 'Macro'->'Securities'->'Trusted ...' Tab,
Check 'Trust the access to Visual Basic Project'
(Note: I'm not sure English UI expression)
I recommend using some anti-virus software.
Thanks for the info. On MSE7 is true I cannot add references but I added
components to see the properties.
I usually use CRedit to do my vbscript but I will be using MSE and the VBE
from excel.
where in japan are you? i'm in Okinawa
Thanks for the help.
Rafael
"Miyahn" <HQF0...@nifty.ne.jp> wrote in message
news:e0BMUfoP...@TK2MSFTNGP14.phx.gbl...
How does intellisense work? I thought it was the little window that appears
to show the properties or methods for the object, but it does not appear
when using vbe.
do I have to enable it too? I'm using early binding.
On MSE it works only when choosing edit/intellisense and selecting....
It would be better if it is automatically like in Visual Basic.
Rafael
"Miyahn" <HQF0...@nifty.ne.jp> wrote in message
news:e0BMUfoP...@TK2MSFTNGP14.phx.gbl...
Check VBE's option.
'Tools' -> 'Options' -> 'Edit' tab.
After typing objectname and dot, autohint will pop up.
For example,
Dim IE As InternetExplorer
Set IE = CreateObject("InternetExplorer.Application")
IE. ____________
| AddressBar |
| Application |
| Busy |
| ... |
BTW, I live in Chiba Pref. Japan.
All the options are checked. This are the options:
auto syntx check
require variable declaration
auto list members
auto quick info
auto data tips
When I type the test you sent me, the auto hint works after the AS and on
the SET line however when I type ie. nothing appears.
If I type ie.load and press enter, it will automatically correct Load
(uppercase L) so it recognized it, just didn't show it to me.
any other idea on what to check?
thanks
Rafael
"Miyahn" <HQF0...@nifty.ne.jp> wrote in message
news:%23lZ2u7w...@TK2MSFTNGP12.phx.gbl...
Hi,
Sorry, I have no idea of any other check point.
What is your Office version?
I have tested Office2K SR1 and Office2002 SP1 and Office2003 noSP,
IntelliSence worked in all that versions.
How about shortcut key, such as Ctrl + J or Ctrl + [Space] ?
Well, since VisualStudio does VBS, I guess there is. :)
Many people like Primal Script as well.
Jeff
Crtl J works but not for objects. If I type IE. and then Ctrl+J it doesn't
do anything.
If I press Ctrl+J on an empty part of the screen it does show something
I have Office XP (2002) no SP
I will keep trying settings.
Thanks
Rafael
"Miyahn" <HQF0...@nifty.ne.jp> wrote in message
news:Ord5sX0P...@tk2msftngp13.phx.gbl...
> ' illegal in VBScript-WSH, but a must here for sensing
> Set WScript = New IHost_Class
I don't get this working. The famous error 429 (ActiveX can't create
object) appears. Any hints to get this working?
Tia,
Sjouke
*** Sent via Developersdex http://www.developersdex.com ***
This declaration and Set statement are not for execution but for
editing with Intelisense support.
So, they should be commented out before execution.