PDA

View Full Version : Excel VBA to Script



Mr.G
12-18-2006, 06:25 AM
Just a general question.........Can one write code in excel and then convert it to script for a website?

malik641
12-18-2006, 07:59 AM
Hey Mr.G.,

I'm assuming you mean VBScript.
I think they could even just write it in VBScript to begin with.

But to answer your question, yes, I'm pretty sure it wouldn't be that hard.


I don't have much experience with VBScript, but check out this site (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/dd5dc02a-71e4-412b-8b30-9cc2d3d5e6fb.asp) for help with scripting if you need it.

HTH :)

tstom
12-18-2006, 02:21 PM
Yes. VB Script is a subset of VBA which is a required library in VB. Of course you still need to know VB Script. Everything is latebound, there are some methods that are available in VBA that are not available in VBScript. VBScript also contains several exclusive methods that will not compile from VBA because they do not belong to the VBA library. There are some free and otherwise cheap editors out there. Depending on your version of Office, you can utilize a great web script editor/debugger. The Microsoft Script Editor. Mine is located here: C:\Program Files\Microsoft Office\OFFICE11\MSE7.EXE

Mr.G
12-19-2006, 12:51 AM
Thanx I'll do some more digging.I'm just interrested to find out.

stanl
12-19-2006, 02:14 PM
Maybe off-topic.. but this thread seems to beg for a discussion of .wsc - after all it is often a preferred COM object for Web stuff, can be instantiated with GetObject() so doesn't require registration, can execuite both VbScript or Jscript and can be modified on the fly.

.02 Stan

Ivan F Moala
12-19-2006, 03:40 PM
Maybe off-topic.. but this thread seems to beg for a discussion of .wsc - after all it is often a preferred COM object for Web stuff, can be instantiated with GetObject() so doesn't require registration, can execuite both VbScript or Jscript and can be modified on the fly.

.02 Stan

That's a good point! also executes PScript, Python, and PERLScript.
not that I am overly familiar with these 3.
I never really considered this basically because I thought that for IE the GetObject function was not supported in script components for security reasons, but I believe you just need to use DHTML.
I have the Script Component Wizard but never really looked further into it.
BUT now that you have mentioned COM/DCOM I think I'll look further into this. Thanks for the prompt!

austenr
12-19-2006, 04:21 PM
I have found some VB Scripts on the Microsoft site to be quite useful. Go to their main page and search for "Hey Scripting Guy". They have quite a few office scripts with good line by line explainations on what the script do.

stanl
12-20-2006, 04:29 AM
I have the Script Component Wizard but never really looked further into it.
BUT now that you have mentioned COM/DCOM I think I'll look further into this. Thanks for the prompt!

That is a neat tool, especially since it generates a unique GUID for each script. I am working on a template to produce .wsc files which in turn will produce xml schema validation files. I found this simple method to produce the GUID


oGUID = CreateObject("Scriptlet.TypeLib")
myGUID = oGUID.GUID
oGUID = Nothing


Stan

Ivan F Moala
12-20-2006, 12:21 PM
That is a neat tool, especially since it generates a unique GUID for each script. I am working on a template to produce .wsc files which in turn will produce xml schema validation files. I found this simple method to produce the GUID


oGUID = CreateObject("Scriptlet.TypeLib")
myGUID = oGUID.GUID
oGUID = Nothing


Stan

Yes :)
and that's a little easier then



Option Explicit

Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type

Private Declare Function CoCreateGuid _
Lib "ole32.dll" ( _
pguid As GUID) _
As Long

Private Declare Function StringFromGUID2 _
Lib "ole32.dll" ( _
rguid As Any, _
ByVal lpstrClsId As Long, _
ByVal cbMax As Long) _
As Long

Sub GenerateGUID()
Dim tGUID As GUID
Dim sGUID As String
Dim bGUID() As Byte
Dim lLen As Long
Dim lRetVal As Long
Dim sGenGUID As String

lLen = 40
bGUID = String(lLen, 0)
CoCreateGuid tGUID
lRetVal = StringFromGUID2(tGUID, VarPtr(bGUID(0)), lLen)
sGUID = bGUID
If (Asc(Mid(sGUID, lRetVal, 1)) = 0) Then lRetVal = lRetVal - 1
sGenGUID = Left(sGUID, lRetVal)

MsgBox sGenGUID
Range("A65536").End(xlUp).Offset(1, 0) = sGenGUID

End Sub