I.T. Discussion Community!
-Collapse +Expand
Delphi
Search Delphi Group:

Advanced
-Collapse +Expand Delphi To/From
To/FromCODEGuides
-Collapse +Expand Delphi Store
PRESTWOODSTORE

Prestwood eMagazine

December Edition
Subscribe now! It's Free!
Enter your email:

   ► MB LobbyPascal and Delphi Coding BoardDelphi COM / ActiveX / DCOM Topic   Print This     

Excel and Word automation

Excel and Word automation in Delphi COM / ActiveX / DCOM topic (part of our Pascal and Delphi Coding group).

Quick Search: automation   Excel Word   Excel Word automation  
JustusJanssen
 (Inactive)
-- NL

Hello everyone,

writing an Office viewer (read-only) application, I dynamically create an TOleContainer on a form and use that to open the Excel or Word file.
Next, the Toolbars (CommandBars) should be made invisible, what I try to accomplish by using Set_Visible(False). For Excel, this works perfectly with the following code:

<code>
   with TOleContainer.Create(Self) do
     begin
       Parent       := Self;
       Left         := 0;
       Top          := 0;
       Align        := alClient;
       AutoActivate := aaManual;
       AutoVerbMenu := False;
       OnDeactivate := OleContainerDeactivate;
       CreateObjectFromFile(sFilename, False);
       DoVerb(ovPrimary);
       WB           := OleObjectInterface as _Workbook;
       iCommandBars := WB.Application.CommandBars.Count;
       with WB.Application do
         for iCommandBar := 1 to iCommandBars do
           begin
             if (CommandBars[iCommandBar].Type_ = 0) then
               CommandBars[iCommandBar].Set_Visible(False);
           end;
       LCID := LOCALE_USER_DEFAULT;
       WB.Application.Interactive[LCID] := False;
       WB.Application.DisplayFormulaBar[LCID] := False;
       UpdateObject;
     end;

</code>

However, when I adapt the code to use Word, it seems to ignore the whole Set_Visible thing. The for ... loop IS executed though:

<code>
   with TOleContainer.Create(Self) do
     begin
       Parent       := Self;
       Left         := 0;
       Top          := 0;
       Align        := alClient;
       AutoActivate := aaManual;
       AutoVerbMenu := False;
       OnDeactivate := OleContainerDeactivate;
       CreateObjectFromFile(sFilename, False);
       DoVerb(ovPrimary);
       Doc          := OleObjectInterface as _Document;
       iCommandBars := Doc.Application.CommandBars.Count;
       with Doc.Application do
         for iCommandBar := 1 to iCommandBars do
           begin
             if (CommandBars[iCommandBar].Type_ = 0) then
               CommandBars[iCommandBar].Set_Visible(False);
           end;
       UpdateObject;
     end;
</code>

I tried replacing the Doc.Application with TWordApplication, like this:

<code>
   WordApplication := TWordApplication.Create(Self);
   WordApplication.ConnectTo(Doc.Application);
</code>

but it didn't change anything. Can anyone help?

Thanks,
   Justus

 Posted 10 years ago (Thread Starter)
Comment Quote
About JustusJanssen -Collapse +Expand
Visit Profile
Inactive member.
Member does not subscribe to this thread.
Old Account!
If this is your account, sign in to activate web presence data (sign in quarterly to keep active). Alternatively, you can subscribe to our monthly eMag with a valid email address.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #13729, 2 reply
Thread Started 11/2/2009 2:17:07 PM
View Counter=8065
Last Reply Posted 12/3/2015 12:18:21 AM)
Location=-- NL 
Joined=16 years ago   MB Posts=1  
Christophe Ravaut
Ieper, -- BE

This works on my pc.

WordDocument1 is a TWordDocument

procedure TForm1.Button1Click(Sender: TObject);
var
   _x: Integer;
   xOleVariant: OleVariant ;
begin
   OleContainer1.CreateObject('WORD.Document', False);
   OleContainer1.Run;
   WordDocument1.ConnectTo( IDispatch(OleContainer1.OleObject)as _Document);
   for _x := 1 To WordDocument1.CommandBars.Count do
   begin
     xOleVariant := _x ;
     if (WordDocument1.CommandBars.Item[xOleVariant].Type_=0) then
     begin

      WordDocument1.CommandBars.Item[xOleVariant].Set_Visible(False) ;
     end;
   end ;
   OleContainer1.DoVerb(ovShow);
end;

 Posted 10 years ago
Comment Quote
About Christophe Ravaut -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.

Post ID #13733 (Level 1.1)  Reply to 13729
Thread Started 11/3/2009 3:10:48 AM
Location=Ieper, -- BE 
Joined=15 years ago   MB Posts=1   KB Comments=1  
Most Recent Post
Anonymous Post

With such an educational blog that proves to be very valuable for others deserves to be shared. I enjoyed reading your post.

---
Johnson
 Posted 48 months ago
Comment Quote

Post ID #15269 (Level 2) and Parent is 13729
Reply Posted 12/3/2015 12:16:35 AM

Revive Thread!

Add a comment to revive this old thread and make this archived thread more useful.

Write a Comment...
Full Editor
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1162A1
Enter key:
Icon: A Post    Thread    Idea    Important!    Cool    Sad    No    Yes    Includes a Link...   
Thread #13729 Counter
8065
Since 11/2/2009

Follow PrestwoodBoards on: 


©1995-2019 PrestwoodBoards  [Security & Privacy]
Professional IT Services: Coding | Websites | Computer Tech