How could I open an existing Excel file and set attribute Read only

Posted on 2003-11-17
Last Modified: 2007-12-19
I use BCB and OLE object "Excel.Application" to open an existing Excel file.
Could I open this existing excel file and set it to be read only through OleProcedure or OleFunction directly?
By the moment, my code is:   Workbook=Workbooks.OleFunction("open", "c:\\test.xls");
it will open an Existing file and could modify data.
I know FileSetAttr Function may make it? But I hope open an file by OleProcedure and set it ReadOnly directly..
Question by:abdate
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 16

Expert Comment

by:George Tokas
ID: 9762923
There is no need to do it through OLE.
You can use "FileSetAttr".
extern PACKAGE int __fastcall FileSetAttr(const AnsiString FileName, int Attr);
Internal help will guide you.


Author Comment

ID: 9765659
Thank you! I know FileSetAttr may do it just I mentioned before. But I wonder Does OLE procedure can do it only change some parameter? If so, I don't need to use FileSetAttr.
LVL 16

Expert Comment

by:George Tokas
ID: 9770068
My opinion is that when you can use native borland calls it is better to do it that way...
Right now I'm working with OLE with Internet explorer and its hell to try 2 find my way due 2 error messages when I link Microsoft's headers.

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 9770117
I read MSDN for opening Excel like the following paragraph:
Sub OpenUp()
End Sub
expression.Open(FileName, UpdateLinks, ReadOnly, Format, Password, WriteResPassword, IgnoreReadOnlyRecommended, Origin, Delimiter, Editable, Notify, Converter, AddToMRU)
How do write in BCB

LVL 16

Accepted Solution

George Tokas earned 50 total points
ID: 9770382
Suppose you have pro or enterprise version >= 5 of BCB.
At the servers page of objects there is ExcelAplication.
The help file (must download as office97 help file) gives explaination on how it is wrapped and how you can work with them...
It will be better if you use the VCL rather than MFC.
To tell the truth for myself I didn't find a way myself YET but I hope in a few days I will.


Expert Comment

ID: 10249262
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: gtokas {http:#9770382}

Please leave any comments here within the next seven days.

EE Cleanup Volunteer

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Quicksort a dynamic deque 33 79
TCP/IP Socket - connection close results in data lost 14 152 build a IF/Then Walkthrough Guide 1 278
sorting efficency of sorting algorithm 30 129
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question