Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OLE automation in excel

Status
Not open for further replies.

madu11

Programmer
Nov 4, 2002
1
0
0
US
I am trying to save an excel sheet in csv format using OLE objects in PB program. How do I reference the save within the excel sheet. Or could you suggest how to manipulate the
excel sheet.(The toatl number of columns is fixed, number of rows is unknown). I keep getting a null object reference error or a error calling external function.

Environment: Windows 2000 professional, PB 6.5

Thanks in Advance.
 
Here is a quick example that opens an XLS file and saves it as a CSV file...Good Luck

OLEObject ole_object
// Create or "Instantiate" the ole_object variable
ole_object = CREATE OLEObject

IF ole_object.ConnectToNewObject("excel.application.8") = 0 THEN
ole_object.Application.DisplayAlerts = "False"
ole_object.workbooks.Open(IS_SPREADSHEET) //Open the .xls file
Else
MessageBox('OLE Error','Unable to start an OLE server process!',Exclamation!)
END IF

// Make Object Invisible
ole_object.Visible=FALSE

//CSV File name
ls_file = "c:\temp\xcel.csv"

FileDelete(ls_file)

// Saves the document to another filename

ole_object.ActiveWorkbook.SaveAs(ls_file, 6) //csv

//ole_object.ActiveWorkbook.SaveAs(ls_file, -4158) //text tab delimited

ole_object.Application.DisplayAlerts = "False"

ole_object.Application.Quit()
// Disconnect from Excel
ole_object.DisconnectObject()
// Destroy the Ole Object
DESTROY ole_object
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top