Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 25

Thread: Command Bars With Custom Face IDs

  1. #1
    Administrator
    VP-Knowledge Base
    VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location

    Question Command Bars With Custom Face IDs

    Hi,

    I have created a CommandBar and attributed some macros to it, but it saves the file name and path for each macro, then I copy the file to another computer and bang all the buttons from the command bar get an error because they are still pointing to the macros in the other computers directory system. The same happens if I change the file name.

    Is there a way to force to button from the command bar to always run only local macros?
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

  2. #2
    VBAX Contributor Richie(UK)'s Avatar
    Joined
    May 2004
    Location
    UK
    Posts
    188
    Location
    Hi,

    How did you create your CommandBar?

    These problems often happen when the menus are created 'manually'. The safest option is to create the menu, buttons and assignments using code that you call in the workbook Open event.

  3. #3
    Administrator
    VP-Knowledge Base VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location
    Hi Richie,

    yes, I have created t manually because I am using images for the buttons. I just use the Enabled event in the workbook_open to show it.


    Any suggestions on how to solve this problem?
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

  4. #4
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    ?? Dont quite understand what you mean. I assume everything including the macros are all getting copied to the other computer also.

    So do you mean that it fails when the code comes to something like Application.Workbooks.Open("C:\Windows\Desktop\Myfolder\MyBook.xls") ??

    (because the other computer may have (say) a drive K: instead of C: )
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  5. #5
    Administrator
    VP-Knowledge Base VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location
    Hi John,

    almost this. At my command bar property attribute macro I have:

    C:\Temp\Carlos.xls!Control

    But at the new computer it should be

    Q:\Casa\Minha.xls!Control

    As I have 7 buttons in this workbook and have to move it very freqently its very bad to have to handle with that manually.
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

  6. #6
    Administrator
    VP-Knowledge Base VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location
    I think maybe the solution could be to use a for..each loop to check every button out of the command bar "Carlos", get its macro path and substitute it by the Application.Path.

    What do you think? Would that be possible?
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

  7. #7
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Thought it may be something like that!!! Have a look here >> KB
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  8. #8
    Administrator
    VP-Knowledge Base VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location
    Hi John,

    thanks I will try to adapt it.
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

  9. #9
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Hi Carlos,

    First off, you could use something like:

    Dim CTL As CommandBarControl, ModMac As String
     For Each CTL In Application.CommandBars("Carlos").Controls
      ModMac = Mid$(CTL.OnAction, InStr(1, CTL.OnAction, "!", 1) + 1)
      CTL.OnAction = "'" & ThisWorkbook.Name & "'" & ModMac
     Next CTL

    But I think you'd have better luck if you created the commandbar when the workbook is loaded, and removed it when closed. That way you're sure that it is always correct. You could use something like:

    Private Sub Workbook_Open()
     On Error Resume Next
     Application.CommandBars("Carlos").Delete
     On Error GoTo 0
     Application.CommandBars.Add "Carlos"
     With Application.CommandBars("Carlos").Controls.Add
      .Caption = "Macro 1"
      .Tag = "Macro 1"
      .OnAction = "'" & ThisWorkbook.Name & "'!ModuleName.MacroName"
     End With
    End Sub
    
    Private Sub Workbook_BeforeClose()
     On Error Resume Next
     Application.CommandBars("Carlos").Delete
    End Sub
    in the ThisWorkbook module.

    Just a thought
    Matt

  10. #10
    Administrator
    VP-Knowledge Base VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location
    Hi Matt,

    it was a good try but didnt work.

    What was:

    Q:\Casa\Minha.xls!Control

    Became:

    'Q:\Casa\Minha.xls'!''Minha.xls'Control

    Any other idea? I cant use your second suggestion because of the buttons images.
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

  11. #11
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    I just realized a mistake in what I had posted. Change my 4th line to:
    CTL.OnAction = "'" & ThisWorkbook.Name & "'!" & ModMac
    (I forgot the ! after the second ' )

  12. #12
    Administrator
    VP-Knowledge Base VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location
    Hi Matt,

    same here. Result:


    Q:\'Minha.xls'!''Minha.xls'Control
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

  13. #13
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Hmmm, odd that it doesn't contain a ! character already.. maybe try:
    Dim CTL As CommandBarControl, ModMac As String
     For Each CTL In Application.CommandBars("Carlos").Controls
      If CTL.OnAction Like "*!*" Then
       ModMac = Mid$(CTL.OnAction, InStr(1, CTL.OnAction, "!", 1) + 1)
      Else
       ModMac = Mid$(CTL.OnAction, InStr(1, CTL.OnAction, ".xls", 1) + 5)
      End If
      CTL.OnAction = "'" & ThisWorkbook.Name & "'!" & ModMac
     Next CTL

  14. #14
    Administrator
    VP-Knowledge Base VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location
    Hi Matt,

    nothing has changed, stills the same.
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

  15. #15
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Hmm, not sure what else it could be without actually being able to try it directly. No way to upload an attachment for this?

  16. #16
    VBAX Contributor Richie(UK)'s Avatar
    Joined
    May 2004
    Location
    UK
    Posts
    188
    Location
    Hi Paleo,

    As suggested above by both Matt and myself, the easiest cure for this problem is to have the menu created by code.

    I don't see what the problem is with the button images. Do you realise that you can use custom images by copying the picture and using PasteFace? Am I missing your point here?

    Example attached.

  17. #17
    Administrator
    VP-Knowledge Base VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location
    Hi Matt and Richie,

    I will post the workbook here.
    How could I use PasteFace if the image wont be at the users computer? Its intended to be sent by mail to many people and I dont plan to create an instalation procedure, wanted to send only the xls file.
    I am thinking about adding the CommandBar with no macros attributed, attribute them by code and delete the attributions before closing the file. What do you think, worth trying?

    Thanks for the attached file Richie I will try to implement it with my solution.
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

  18. #18
    VBAX Contributor Richie(UK)'s Avatar
    Joined
    May 2004
    Location
    UK
    Posts
    188
    Location
    Quote Originally Posted by Paleo
    ... How could I use PasteFace if the image wont be at the users computer? Its intended to be sent by mail to many people and I dont plan to create an instalation procedure, wanted to send only the xls file.
    Hi Paleo,

    The image is attached to a worksheet in the workbook that contains the code (see the example in the workbook that I attached )

  19. #19
    Administrator
    VP-Knowledge Base VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location
    Hi Richie,

    there is no picture attached to in the workbook you posted. Its simply using an excel built in picture (code 59, smile), What I need is a function to insert buttons using images other than those provided by excel. I am using images created by me. Any suggestions?
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

  20. #20
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Carlos, is the problem with the creation code? Or are you just talking about the FaceId's?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •