I am using OLE to manipulate an existing xls spreadsheet file in Excel 12
from PB 11.2 and XP.
I have no problem opening and manipulating the spreadhseet file whatsoever.
My problem lies in trying to Save() the workbook. With just the Save()
method, it only saves a copy of the file in the My Documents folder. If I
try the SaveAs() method, it prompts for a filename in the current folder,
but the filename is always prefixed with "Copy of " and the existing
filename - the SaveAs() is not desirable.
What I would like is to simply save the existing file, after I've
manipulated it, using the existing filename and the existing folder.
TIA,
Bob
This is what I'm currently doing:
integer li_Return
string ls_Filename
string ls_Sheet
OLEObject ole_object
OLEObject ole_sheet
ole_object = CREATE OLEObject
ls_Filename = 'C:\Documents and Settings\rpr\Desktop\Test.xls'
IF ole_object.ConnectToNewObject("excel.application") = 0 THEN
ole_object.Application.DisplayAlerts = "False"
ole_object.Visible=FALSE
ole_object.workbooks.Open(ls_Filename)
ls_Sheet = 'MobiLink_SPs'
ole_sheet = ole_object.Application.ActiveWorkbook.WorkSheets(ls_Sheet)
ole_sheet.Activate
ole_sheet.Unprotect ("pw")
ole_sheet.Rows("4:4").Select
ole_sheet.Rows("4:4").Insert( -4121, 0)
ole_sheet.Range("A4").Select
ole_sheet.Range("A4").FormulaR1C1 = "TEST5"
ole_sheet.Range("B4").Select
ole_sheet.Range("B4").FormulaR1C1 = "Test5"
ole_sheet.Protect("pw", TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)
ole_object.ActiveWorkbook.Save()
ole_object.ActiveWorkbook.Close()
ELSE
MessageBox('OLE Error','Unable to start an OLE server
process!',Exclamation!)
RETURN
END IF
ole_object.Application.Quit()
ole_sheet.DisconnectObject()
ole_object.DisconnectObject()
DESTROY ole_object
DESTROY ole_sheet
Your original spreadsheet file is probably ReadOnly, or perhaps it's in a
network folder that has ReadOnly access.
I was just experimenting with the same kind of project today and found that
it saves it to My Documents if the original is ReadOnly, but it overwrites
the original file if the user is authorized to do so.
thanks,
Pat
"Robert Regnell" <r...@lebcopage.com> wrote in message
news:4aeaed73@forums-1-dub...