INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Usefull Functions & Procedures

How to get all the Excel or Word constants with their values by mgagnon
Posted: 2 Oct 03 (Edited 3 Oct 03)

Note this applies to VFP7.0 or VFP8.0 (For VFP6.0 and VFP5.0 see below)

Here is a place to look for the Excel or Word constants into a header file. This also applies to the other application in the Microsoft Office suite.
  1. In the command window of VFP create a program with an ".h" extension.
    MODIFY COMMAND oXContants.h

  2. Leaving the you just created onpened,open the Object Browser (Tools->Object browser)

  3. Use the left-most button in the object browser (Open Type library) and select the COM library, and click on the Microsoft Excel XX object type library and click OK.

  4. Expand the Excel library and locate the constants.

  5. Drag the constant directory to the opened program. In a second all the Excel constant will paste themselves into the program with the constant value you can use in VFP.


I give credit to Celtin Basoz for some of this information.

_________________________________________________________

For those of you who use VFP5.0 or VFP6.0 here is how to do it. Copy the following into a program and run it.
This code was modified from MSDN to work in VFP5.0 (ie. Createobject rather than NEWOBJJECT and ALLTRIM(STR()) rather than TRANSFORM).

PUBLIC oform1

oform1=createOBJECT("form1")
oform1.SHOW
RETURN
DEFINE CLASS form1 AS FORM
    HEIGHT = 445
    WIDTH = 567
    DOCREATE = .T.
    AUTOCENTER = .T.
    BORDERSTYLE = 1
    CAPTION = ".OLB Constants Extractor"
    MAXBUTTON = .F.
    MINBUTTON = .F.
    NAME = "Form1"
    ADD OBJECT txtolbfile AS TEXTBOX WITH ;
        HEIGHT = 27, ;
        LEFT = 65, ;
        READONLY = .T., ;
        TABINDEX = 2, ;
        TOP = 6, ;
        WIDTH = 458, ;
        NAME = "txtOLBFILE"
    ADD OBJECT label1 AS LABEL WITH ;
        AUTOSIZE = .T., ;
        CAPTION = ".\<OLB File:", ;
        HEIGHT = 17, ;
        LEFT = 4, ;
        TOP = 11, ;
        WIDTH = 55, ;
        TABINDEX = 1, ;
        NAME = "Label1"
    ADD OBJECT cmdsave AS COMMANDBUTTON WITH ;
        TOP = 411, ;
        LEFT = 394, ;
        HEIGHT = 27, ;
        WIDTH = 84, ;
        CAPTION = "\<Save to .h", ;
        ENABLED = .F., ;
        TABINDEX = 6, ;
        NAME = "cmdSAVE"
    ADD OBJECT cmdquit AS COMMANDBUTTON WITH ;
        TOP = 411, ;
        LEFT = 480, ;
        HEIGHT = 27, ;
        WIDTH = 84, ;
        CAPTION = "\<Quit", ;
        TABINDEX = 7, ;
        NAME = "cmdQUIT"
    ADD OBJECT edtconstants AS EDITBOX WITH ;
        HEIGHT = 347, ;
        LEFT = 6, ;
        READONLY = .T., ;
        TABINDEX = 4, ;
        TOP = 52, ;
        WIDTH = 558, ;
        NAME = "edtConstants"
    ADD OBJECT cmdgetfile AS COMMANDBUTTON WITH ;
        TOP = 6, ;
        LEFT = 533, ;
        HEIGHT = 27, ;
        WIDTH = 26, ;
        CAPTION = "...", ;
        TABINDEX = 3, ;
        NAME = "cmdGETFILE"
    ADD OBJECT cmdextract AS COMMANDBUTTON WITH ;
        TOP = 411, ;
        LEFT = 280, ;
        HEIGHT = 27, ;
        WIDTH = 110, ;
        CAPTION = "\<Extract Constants", ;
        ENABLED = .F., ;
        TABINDEX = 5, ;
        NAME = "cmdEXTRACT"
    PROCEDURE cmdsave.CLICK
        STRTOFILE(THISFORM.edtconstants.VALUE,PUTFILE([Header File], ;
            JUSTSTEM(THISFORM.txtolbfile.VALUE) + [.h],[.h]))
    ENDPROC
    PROCEDURE cmdquit.CLICK
        THISFORM.RELEASE
    ENDPROC
    PROCEDURE cmdgetfile.CLICK
        LOCAL lcOLBFile
        lcOLBFile = GETFILE([OLB],[OLB File],[Open])
        IF EMPTY(lcOLBFile)
            RETURN .F.
        ENDIF
        IF UPPER(RIGHT(lcOLBFile,3)) # [OLB]
            MESSAGEBOX([Invalid File],0,[])
            RETURN .F.
        ENDIF
        THISFORM.txtolbfile.VALUE = lcOLBFile
        THISFORM.cmdextract.ENABLED= .T.
    ENDPROC
    PROCEDURE cmdextract.CLICK
        WAIT WINDOW [Processing...] NOCLEAR NOWAIT
        LOCAL oTLB_INFO, oConstants, lcConstantsStr, Obj, member
        #DEFINE CRLF CHR(13) + CHR(10)
        oTLB_INFO = CREATEOBJECT([tli.typelibinfo])
        oTLB_INFO.ContainingFile = (THISFORM.txtolbfile.VALUE)
        oConstants = oTLB_INFO.Constants
        lcConstantsStr = []
        FOR EACH Obj IN oTLB_INFO.Constants
                        lcConstantsStr = lcConstantsStr + CRLF + "* " + Obj.Name + CRLF   
                        FOR EACH member IN Obj.Members
                            lcConstantsStr = lcConstantsStr + [#DEFINE ] + ;
                            member.NAME + [ ] + ;
                            alltrim(str(member.VALUE)) + CRLF
                        NEXT member
        NEXT Obj
        THISFORM.edtconstants.VALUE=lcConstantsStr
        THISFORM.cmdsave.ENABLED= .T.
        WAIT CLEAR
        WAIT WINDOW [Complete!] TIMEOUT 2
    ENDPROC

ENDDEFINE


Mike Gagnon


Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close