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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VFP Excel Automation - ReadOnly Test 1

Status
Not open for further replies.

JRB-Bldr

Programmer
May 17, 2001
3,281
US
I have been trying to find a solution to having VFP Automation of Excel perform an initial test to check if the Workbook just opened was opened as ReadOnly due to someone else having the file open.

Unfortunately what I have found so far through web searches has not worked.

Originally, based on findings on the web, I was trying the following (but it did not work):
Code:
tmpsheet = CREATEOBJECT('excel.application')
oExcel = tmpsheet.APPLICATION
oExcel.Workbooks.OPEN(ADDBS(cReportDir) + cExcelFile)
oExcel.WINDOWS(cExcelFile).ACTIVATE
IF [B]oExcel.ReadOnly[/B]
   <do something>
ENDIF

The oExcel.ReadOnly threw an
OLE code error - unknown object

Next by wandering around through the oExcel object properties I thought that I found the answer, but it too did not work:
Code:
tmpsheet = CREATEOBJECT('excel.application')
oExcel = tmpsheet.APPLICATION
oExcel.Workbooks.OPEN(ADDBS(cReportDir) + cExcelFile)
oExcel.WINDOWS(cExcelFile).ACTIVATE
IF [B]oExcel.ThisWorkbook.ReadOnly[/B]
   <do something>
ENDIF

But oExcel.ThisWorkbook.ReadOnly threw an
OLE IDispatch exception code 0 from Microsoft Excel - Unable to get ThisWorkbook property of the Application class...

I have a strong suspicion that there is a test that I can perform, but I have yet to find the right combination of objects and properties to do the job.

As always, any advice you might have to give would be greatly appreciated.

Thanks,
JRB-Bldr

 
Thanks Mike that worked.

Thanks,
JRB-Bldr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top