Board index » delphi » Using Delphi to create a command button in Excel

Using Delphi to create a command button in Excel

Hi,
I posted the below a couple of weeks ago, but no response - can anyone help
please?

Is it possible to do this using Early binding? (D6)
Can someone give me an example?
TIA
Hugh Butcher

 

Re:Using Delphi to create a command button in Excel


If u wanna add ur own toolbar/button to Excel u need to implement a Com
Addin
u can read about it in msdn also there are lots of examples in delphi for it
on the net

as for early binding ..of course u can do this in delphi, dont use
OleVariants
use the interfaces explicitly, import the Excel headers

for example
procedure aaa()
var
    ExcelApp: ExcelApplication
    ExcelAppVAr: OLeVariant;
begin
    //this is early binding
    ExcelApp := CoExcelApplication.Create;
    //This is late binding
    ExcelAppVar := CreateOleObject('Excel.Application');
    ect.....
end;

hope this helps
Daniel

Quote
"Hugh Butcher" <butch...@acnielsen.co.nz> wrote in message

news:3d03b94d_1@dnews...
Quote
> Hi,
> I posted the below a couple of weeks ago, but no response - can anyone
help
> please?

> Is it possible to do this using Early binding? (D6)
> Can someone give me an example?
> TIA
> Hugh Butcher

Re:Using Delphi to create a command button in Excel


<<Hugh Butcher:
Is it possible to do this using Early binding? (D6)

Quote

Add buttons, toolbars etc? Yes.

var
  NewToolbar: CommandBar;
  ToolbarItem: CommandBarControl;

  { Create temporary toolbar - set last parameter to
    False to make a permanent toolbar }
  NewToolBar := Excel.CommandBars.Add(
    'MyToolbar',msoBarTop, False, True);
  OleVariant(NewToolbar).Visible := True;

  { Add a button }
  ToolbarItem :=
    NewToolbar.Controls.Add(msoControlButton, EmptyParam,
                            EmptyParam, EmptyParam, True);
  ToolbarItem.Set_TooltipText('Show success');
  OleVariant(ToolbarItem).FaceID := 2;

  { Assign a macro to the button }
  OleVariant(ToolbarItem).OnAction
    := 'ThisWorkbook.ShowSuccess';

--
Deborah Pate (TeamB) http://delphi-jedi.org

  TeamB don't see posts sent via Google or ISPs
  Use the real Borland server: newsgroups.borland.com
  http://www.borland.com/newsgroups/genl_faqs.html

Re:Using Delphi to create a command button in Excel


Deborah,

thanks for the reply. Problem is the compiler (D6 E) does not like the
reference to 'CommandBar' or 'CommandbarControl', neither can I find either
word in the C:\Program Files\Borland\Delphi6\Source\*.pas source files. Can
you explain please what to to get this to work?

Thanks for your help on this and previous queries

Hugh

"Deborah Pate (TeamB)" <d.p...@blueyonder.co.not-this-bit.uk> wrote in
message news:VA.00001391.00d951a1@blueyonder.co.not-this-bit.uk...

Quote
> <<Hugh Butcher:
> Is it possible to do this using Early binding? (D6)

> Add buttons, toolbars etc? Yes.

> var
>   NewToolbar: CommandBar;
>   ToolbarItem: CommandBarControl;

>   { Create temporary toolbar - set last parameter to
>     False to make a permanent toolbar }
>   NewToolBar := Excel.CommandBars.Add(
>     'MyToolbar',msoBarTop, False, True);
>   OleVariant(NewToolbar).Visible := True;

>   { Add a button }
>   ToolbarItem :=
>     NewToolbar.Controls.Add(msoControlButton, EmptyParam,
>                             EmptyParam, EmptyParam, True);
>   ToolbarItem.Set_TooltipText('Show success');
>   OleVariant(ToolbarItem).FaceID := 2;

>   { Assign a macro to the button }
>   OleVariant(ToolbarItem).OnAction
>     := 'ThisWorkbook.ShowSuccess';

> --
> Deborah Pate (TeamB) http://delphi-jedi.org

>   TeamB don't see posts sent via Google or ISPs
>   Use the real Borland server: newsgroups.borland.com
>   http://www.borland.com/newsgroups/genl_faqs.html

Re:Using Delphi to create a command button in Excel


this is in the office headers not in the excel header file

Quote
"Hugh Butcher" <butch...@acnielsen.co.nz> wrote in message

news:3d058ae4$1_1@dnews...
Quote
> Deborah,

> thanks for the reply. Problem is the compiler (D6 E) does not like the
> reference to 'CommandBar' or 'CommandbarControl', neither can I find
either
> word in the C:\Program Files\Borland\Delphi6\Source\*.pas source files.
Can
> you explain please what to to get this to work?

> Thanks for your help on this and previous queries

> Hugh

> "Deborah Pate (TeamB)" <d.p...@blueyonder.co.not-this-bit.uk> wrote in
> message news:VA.00001391.00d951a1@blueyonder.co.not-this-bit.uk...
> > <<Hugh Butcher:
> > Is it possible to do this using Early binding? (D6)

> > Add buttons, toolbars etc? Yes.

> > var
> >   NewToolbar: CommandBar;
> >   ToolbarItem: CommandBarControl;

> >   { Create temporary toolbar - set last parameter to
> >     False to make a permanent toolbar }
> >   NewToolBar := Excel.CommandBars.Add(
> >     'MyToolbar',msoBarTop, False, True);
> >   OleVariant(NewToolbar).Visible := True;

> >   { Add a button }
> >   ToolbarItem :=
> >     NewToolbar.Controls.Add(msoControlButton, EmptyParam,
> >                             EmptyParam, EmptyParam, True);
> >   ToolbarItem.Set_TooltipText('Show success');
> >   OleVariant(ToolbarItem).FaceID := 2;

> >   { Assign a macro to the button }
> >   OleVariant(ToolbarItem).OnAction
> >     := 'ThisWorkbook.ShowSuccess';

> > --
> > Deborah Pate (TeamB) http://delphi-jedi.org

> >   TeamB don't see posts sent via Google or ISPs
> >   Use the real Borland server: newsgroups.borland.com
> >   http://www.borland.com/newsgroups/genl_faqs.html

Other Threads