Discussion Locked

Foxpro program generating Excel Forms

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I need to write a FoxPro program that will generate different forms in Excel. Basically, the program will get some variables such as field names and lengths then it will publish the fields in Excel on a spreadsheet that can be saved to disk for dataentry. The column names will have to be locked so they cannot be changed. Any suggestions?

6 replies

by shais rosenblatt

If you're using Visual FoxPro, you can easily use Automation to control Excel.

Here's a code snippet to get you started:

LOCAL lcErrorHandler, llErrorOccurred, ;
loExcel, loThisSheet

lcErrorHandler = ON("ERROR")
llErrorOccurred = .F.
ON ERROR llErrorOccurred = .T.
loExcel = GETOBJECT(, "Excel.Application")
IF llErrorOccurred
llErrorOccurred = .F.
loExcel = CREATEOBJECT;
("Excel.Application")
ENDIF
ON ERROR &lcErrorHandler
loExcel.Visible = .T.
loExcel.Workbooks.Add()
loThisSheet = ;
loExcel.ActiveWorkBook.ActiveSheet
WITH loThisSheet
.Name = "My Data Entry Form"
.Range("A1").Value = "A Header"
.Range("A2").Select
ENDWITH
loExcel.ActiveWindow.FreezePanes = .T.
The VB for Excel help file should be a good reference to help you figure out how to do what you need . . .

by shaisr

Hmmm. It looks like the formatting wasn't saved. Maybe we can try that again:

LOCAL lcErrorHandler, llErrorOccurred, ;
    loExcel, loThisSheet

lcErrorHandler = ON("ERROR")
llErrorOccurred = .F.
ON ERROR llErrorOccurred = .T.
loExcel = GETOBJECT(, "Excel.Application")
IF llErrorOccurred
    llErrorOccurred = .F.
    loExcel = CREATEOBJECT;
        ("Excel.Application")
ENDIF
ON ERROR &lcErrorHandler
loExcel.Visible = .T.
loExcel.Workbooks.Add()
loThisSheet = ;
    loExcel.ActiveWorkBook.ActiveSheet
WITH loThisSheet
    .Name = "My Data Entry Form"
    .Range("A1").Value = "A Header"
    .Range("A2").Select
ENDWITH
loExcel.ActiveWindow.FreezePanes = .T.

Hope this helps . . .

by shaisr

Nope, still didn't work. Hope you can figure out where the line breaks should be, though . . .

This discussion is closed to new replies.