Excel.inc?

A

Agoston Bejo

Hi, is there somewhere a file that holds constants for Excel Automation
ActiveX objects, such as adovbs.inc for ADO constants?

Thx
 
C

Christoph Basedau

Hi, is there somewhere a file that holds constants for Excel Automation
ActiveX objects, such as adovbs.inc for ADO constants?

You could extract the constants from the typelib and write them
to file:


Option Explicit

Dim fs
Set fs = CreateObject("Scripting.FileSystemObject")

'Creates two IncludeFiles
CreateIncludeFile "Excel.Application", "vbs", "C:\xlsConsts.vbs", true
CreateIncludeFile "Excel.Application", "js", "C:\xlsConsts.js", true

Sub CreateIncludeFile (sProgID, scrID, sOutFile, bShowImmediate)
Dim strConsts
strConsts = ReturnTlbEnumsFromProgId (sProgID, scrID)
fs.CreateTextFile(sOutFile, true, 0).Write strConsts
If bShowImmediate Then CreateObject("WScript.Shell").Run "notepad " & sOutFile
End Sub

Function ReturnTlbEnumsFromProgId (sProgId, scrID)
'Thx Alex ;-)
Dim TLA, TLI, CstEnum, CstObj, CstString, CoCls, vCst, vEndl, vCmt
Set CoCls = CreateObject(sProgId)
Set TLA = CreateObject("TLI.TLIApplication")
Set TLI = TLA.InterfaceInfoFromObject(CoCls).Parent
Call getLangParams (scrID, vCst, vEndl, vCmt)
CstString = BuildIntro (sProgId, TLI.ContainingFile, vCmt)
For each CstEnum in TLI.Constants
If "_" <> Left(CstEnum.Name, 1) Then
CstString = CstString & vbCrlf & vCmt & CstEnum.Name & vbCrlf
For Each CstObj In CstEnum.Members
CstString = CstString & vCst & " " & CstObj.Name _
& " = " & CstObj.Value & vEndl & vbCrLf
Next
End If
Next
ReturnTlbEnumsFromProgId = CstString
End Function

Sub getLangParams (ByVal scrID, ByRef vCst, ByRef vEndl, ByRef vCmt)
Select Case LCase(scrID)
Case "vbs", "vbscript":
vCst = "Const" : vEndl = "" : vCmt = "'"
Case "js", "jscript":
vCst = "var" : vEndl = ";" : vCmt = "//"
Case Else
vCst = "" : vEndl = "" : vCmt = ""
End Select
End Sub

Function BuildIntro (sProgId, srv, vCmt)
BuildIntro = vCmt & String (60, "*") & vbCrLf _
& vCmt & "Enumerated Constants for CoClass """ & sProgID & """" & vbCrLf _
& vCmt & "Extracted from """ & srv & """" & vbCrLf _
& vCmt & String (60, "*") & vbCrLf
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top