Using Word VBA variables in VB6

A

Amir

Hi,



I'm using Visual Basic Studio 6 in order to build installation program for
my macro/template.



The installation program copies the template to the Startup directory of
Word, and adds appropriate command bars buttons.



My question is how should I declare the variables in VB in order to do that?



As opposed to VBA, in VB I am not able to declare the following types of
variables: CommandBarPopup, CommandBarButton, CommandBarControl, CommandBar,
KeyBinding.



In VBA, I would have used:



Dim objCmdBrPp As CommandBarPopup, objCmdBtn As CommandBarButton
Dim myCustom As CommandBarControl, cbcMenuBar As CommandBar
Dim iHelpIndex As Integer, kbNew As KeyBinding
Const strMenuName As String = "MyMenu"

Application.CommandBars("Menu Bar").Controls(strMenuName).Delete
CommandBars.DisplayTooltips = True

Set cbcMenuBar = Application.CommandBars("Menu Bar")
iHelpIndex = cbcMenuBar.Controls("Help").Index

Set myCustom = cbcMenuBar.Controls.Add(Type:=msoControlPopup,
Before:=iHelpIndex)

With myCustom
.Caption = strMenuName

With .Controls.Add(Type:=msoControlButton)
.Caption = "MyCaption"
.OnAction = "macro1"
.FaceId = 9678
.ShortcutText = "Alt+Ctrl+A"
Set kbNew = KeyBindings.Add(KeyCategory:=wdKeyCategoryCommand, _
Command:="Document_Open", KeyCode:=BuildKeyCode(wdKeyControl, wdKeyAlt,
wdKeyA))







Kind Regards,
Amir.
 
J

Jonathan West

Hi amir,

Word is an ActiveX server, and so you can address this just like any oher
ActiveX DLL. You can use early binding or late binding

These articles will help you.

Control Word from Excel
http://www.word.mvps.org/FAQs/InterDev/ControlWordFromXL.htm


Early vs. Late Binding
http://www.word.mvps.org/FAQs/InterDev/EarlyvsLateBinding.htm

Don't worry about the reference to controlling Word from Excel, the
principles are exactly the same when controlling Word from VB6.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
A

Amir

Thanks Jonathan,

That article about Early vs. Late Binding was the exact thing I was looking
for.
The only thing I couldn't find there is about GetObject.

It says that:
Set Set oXL = New Excel.Applicationis
is the equivalent to:
Set oXL = CreateObject("Excel.Application")

but is there equivalent early binding command for:
Set oXL = GetObject(, "Excel.Application")?

Kind Regards,
Amir.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top