Advertisement

05.02.2007 at 09:43PM PDT, ID: 22549511
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.4

MS Word Add-In Hell - Multiple msoCommandButtons

Asked by dds110 in Visual Basic Programming, VB Controls, Microsoft Word

Tags: ,

THIS IS A VB6 ADD-IN FOR MS WORD!!!!

I've been trying to figure this out for several hours now to no avail.  What I'm trying to do is add a button to a new CommandBar for each printer attached to my system.  Each button will have the same .OnAction.  What's happening is only the last button created is getting the .OnAction property assigned (so I know it works).  If the buttons weren't Office CommandBarButtons, I could create a button array, but NNNNOOOOOOOOOOOOO, Microsoft was having none of that.

So the basic question is this:  How do I assign a new button to the commandbar and assigne each button to the same OnAction event?  Here's my code!!!  (forgive me for posting all of it).

Option Explicit
Public oWord As Object
Public WithEvents button As Office.CommandBarButton


Private Sub AddinInstance_OnConnection(ByVal Application As Object, ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As Object, custom() As Variant)
On Error Resume Next
Set oWord = Application
Dim pb As Object                            'new command bar
Dim p As Printer                            'printer object
Dim pName As String                         'printer name without the path

Set pb = oWord.CommandBars("Printbar")      'does the commandbar exist?
If pb Is Nothing Then
  Err.Clear                                 'if we got here, it doesn't
  Set pb = oWord.CommandBars.Add("Printbar") 'create it
  pb.Visible = True                         'let's see it
End If

For Each p In Printers                                              'create a new button for each printer in the printers collection
  pName = Mid(p.DeviceName, InStrRev(p.DeviceName, "\") + 1)
  Set button = oWord.CommandBars.FindControl(, , pName)             'does the button already exist?
  If button Is Nothing Then
    Set button = oWord.CommandBars("Printbar").Controls.Add(1)      'no? Let's create it
    button.Tag = pName
    button.Parameter = pName
    button.Caption = pName
    button.Style = msoButtonCaption
    button.OnAction = "!<" & AddInInst.ProgId & ">"                 'this is what we do when we click it!
    button.Visible = True                                           'gotta see it to click it
  End If
Next p

End Sub

Private Sub AddinInstance_OnDisconnection(ByVal RemoveMode As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
On Error Resume Next
Set button = Nothing
Set oWord = Nothing
End Sub

Private Sub button_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
MsgBox Ctrl.Parameter           'msgbox to see if it's working
End Sub
Start Free Trial
 
Loading Advertisement...
 
[+][-]05.03.2007 at 11:40AM PDT, ID: 19025699

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.03.2007 at 12:37PM PDT, ID: 19026159

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.08.2007 at 11:59AM PDT, ID: 19052241

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Visual Basic Programming, VB Controls, Microsoft Word
Tags: word, vb6
Sign Up Now!
Solution Provided By: dds110
Participating Experts: 1
Solution Grade: B
 
 
[+][-]05.08.2007 at 12:28PM PDT, ID: 19052399

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.08.2007 at 05:09PM PDT, ID: 19053930

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32