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

Reply via email to