我想在 Word 、Excel 中加入一个工具栏,再加上一个按钮,就象金山软件一样,怎么做呢??(100分)

  • 主题发起人 主题发起人 netwinds
  • 开始时间 开始时间
N

netwinds

Unregistered / Unconfirmed
GUEST, unregistred user!
我想在 Word 、Excel 中加入一个工具栏,再加上一个按钮,就象金山软件一样,怎么做呢??
 
你可以用olecontainer 把word和excel嵌入即可.
 
给你一个加菜单的。

61. 操作WORD菜单
以下程序在Word 2000的“文件”菜单前添加“Custom”菜单,
并在其下添加“Import”菜单项。
请仔细研究,我已经调试通过。

uses ...,ComObj;

procedure TForm1.Button1Click(Sender: TObject);
var
WordApp,
myMenuBar,
newMenu,
ctrl1:OleVariant;
begin
WordApp :=CreateOleObject('Word.application');
WordApp.visible:=true;
myMenuBar :=WordApp.CommandBars.ActiveMenuBar;
newMenu := myMenuBar.Controls.Add(10,1,1,1,true);
newMenu.Caption := 'Custom';
ctrl1 := newMenu.CommandBar.Controls.Add(1,1,0,1,false);
ctrl1.Caption := 'Import';
ctrl1.TooltipText := 'Import';
ctrl1.Style := 2;
end;


 
我不是要这个啦。我是想用COM扩展来做,就是做一个动态库,当office打开时就会
自动加一个工具栏的

再找高手
 
高手哪去了?
 
买一本《DELPHI深度探索》,那上面有MS Office的COM ADDIN技术
 
哦!但我较急!
 
谁有电子书呢?提供一个下载的地址吧?
 
建议你到这里看看,有很多你想要的东西.
http://www.execlhome.net
 
乱七八糟的,根本就进不去
 
用vba可以解决的
 
我想要用DELPHI来做,但不知怎么做?

另,请给个具体的例子,让我学一学,OK?
 
以下是我一年前用Excel 宏代码写的或许对你有用.
Excel 之家 http://www.excelhome.net/

'本软件的作者:王永强
'电邮:nmfx1122@163.net
'本软件未经授权属非法使用

Const myFxTools As String = "阿飞工具软件 V1.1"

Sub createmenu()

Application.Caption = "阿飞工具软件 V1.1"

Dim cbMenu As CommandBarControl
Dim cbSubMenu As CommandBarControl
Dim RMenu As CommandBarPopup

RemoveMenu
Set cbMenu = Application.CommandBars(1).Controls.Add(msoControlPopup, , , , True)
With cbMenu
.Caption = "FxTools1.1(&M)"
.Tag = "MyTag1"
.BeginGroup = False
End With

If cbMenu Is Nothing Then Exit Sub

With cbMenu.Controls.Add(msoControlButton, 1, , , True)
.Caption = "自动补充"
.OnAction = "fx_selection"
.BeginGroup = True

End With

With cbMenu.Controls.Add(msoControlButton, 1, , , True)
.Caption = "计算器"
.OnAction = "callcale"
End With
With cbMenu.Controls.Add(msoControlButton, 1, , , True)
.Caption = "关于本软件"
.OnAction = "xjm"
End With
Set cbSubMenu = Nothing
Set cbMenu = Nothing
End Sub
Sub RemoveMenu()
DeleteCustomCommandBarControl "Mytag1"

End Sub

Private Sub DeleteCustomCommandBarControl(customcontroltag As String)
On Error Resume Next
Do
Application.CommandBars.FindControl(, , customcontroltag, False).Delete
Loop Until applicon.FindControl(, , customcontroltag, False) Is Nothing
On Error GoTo 0

End Sub
Sub ShowHideMenu(menuvisible As Boolean)
changecontrolvisibility "mytag1", menuvisible

End Sub
Private Sub changecontrolvisiblility(customcontroltag As String, menuvisible As Boolean)
On Error Resume Next
Application.CommandBars.FindControl(, , customcontroltag, False).Visible = menuvisible
On Error GoTo 0

End Sub
Sub RMenu()
Application.CommandBars("Cell").Reset

Dim Fmenu As CommandBarControl
Set Fmenu = Application.CommandBars("cell").Controls.Add(, , , before:=9)
With Fmenu
.Caption = "自动补充"
.OnAction = "fx_selection"
.BeginGroup = True
.FaceId = 59

End With

End Sub
Sub MenubarReset()
MenuBars(xlWorksheet).Reset

End Sub
Sub MacroName()

MsgBox "this could be macro running!", vbInformation, ThisWorkbook.Name

End Sub

Sub FxMenu()
DeleteFxMenu
Dim cbar1 As CommandBar
Dim cbMenu As CommandBarPopup
Dim cbButton As CommandBarButton

Set cbar1 = Application.CommandBars.Add(myFxTools, msoBarTop, False, True)
Set cbButton = cbar1.Controls.Add(msoControlButton, , , , True)
With cbButton
.Caption = "自动补充"
.FaceId = 59
.Style = msoButtonIcon
.OnAction = "fx_selection"
.TooltipText = "自动补充空白内容"
End With
Set cbButton = cbar1.Controls.Add(msoControlButton, , , , True)
With cbButton
.Caption = "选定内容打印"
.Style = msoButtonIconAndCaption
.FaceId = 63
.OnAction = "fx_selectionprint"
.TooltipText = "打印选定内容"
.BeginGroup = True

End With
Set cbButton = cbar1.Controls.Add(msoControlButton, , , , True)
With cbButton
.Caption = "关于"
.Style = msoButtonCaption
.FaceId = 7
.OnAction = "xjm"
.TooltipText = "关于本软件"
End With

cbar1.Visible = True


End Sub
Sub DeleteFxMenu()
On Error Resume Next
Application.CommandBars(myFxTools).Delete
On Error GoTo 0

End Sub

Sub callCale()
'Shell "cale.exe", vbNormalFocus
Dim RetVal
RetVal = Shell("CALC.EXE", 1)

End Sub
Sub fx_selection()
Dim mycell As Range

For Each mycell In Selection
'Selection.PrintOut Copies:=1, Preview:=True, Collate:=True


If mycell = "" Then mycell.Formula = "=R[-1]c"


Next mycell

End Sub
Sub fx_selectionprint()
Selection.PrintOut copies:=1, preview:=True, collate:=True
End Sub
Sub XJM()
frmXJM.Show


End Sub

 
你把我和jsxjd的代码结合起来就是你要的东西。
 
不行的。我是想做一个库文件(COM),不管你自己的软件有没有运行,只要启动word后就
会自动出现一个菜单或工具栏的
 
你直接在Excel中写宏代码好了。
我的代码直接可以用。
 
学习来了!
 
不行的。我是想做一个库文件(COM),不管你自己的软件有没有运行,只要启动word后就
会自动出现一个菜单或工具栏的

象金山毒霸一样
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部