Consulting

Page 2 of 3 FirstFirst 1 2 3 LastLast
Results 21 to 40 of 52

Thread: Solved: Custom Floating Menu Bar

  1. #21
    Site Admin
    The Princess
    VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Okay. The Grandson decided to stay this weekend so, of course, I didn't get much done. He's 19 months old.

    I'm back on it now. (No whip-cracking, Jake!)
    ~Anne Troy

  2. #22
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    According to the MVPs, I ought to be able to use a dialog:

    [vba]With Dialogs(wdDialogFormatBordersAndShading)
    .ApplyTo = 3
    .Shadow = 0
    .Shading = 0
    .Foreground = 0
    .Background = 0
    .LeftStyle = 0
    .RightStyle = 0
    .TopStyle = 0
    .BottomStyle = 0
    .HorizStyle = 0
    .VertStyle = 0
    .Execute
    End With[/vba]

    instead of this:
    [vba]With .Borders(wdBorderLeft)
    .LineStyle = wdLineStyleSingle
    .LineWidth = wdLineWidth050pt
    .Color = wdColorAutomatic
    End With
    With .Borders(wdBorderRight)
    .LineStyle = wdLineStyleSingle
    .LineWidth = wdLineWidth050pt
    .Color = wdColorAutomatic
    End With
    With .Borders(wdBorderTop)
    .LineStyle = wdLineStyleSingle
    .LineWidth = wdLineWidth050pt
    .Color = wdColorAutomatic
    End With
    With .Borders(wdBorderBottom)
    .LineStyle = wdLineStyleSingle
    .LineWidth = wdLineWidth050pt
    .Color = wdColorAutomatic
    End With
    With .Borders(wdBorderHorizontal)
    .LineStyle = wdLineStyleSingle
    .LineWidth = wdLineWidth050pt
    .Color = wdColorAutomatic
    End With
    With .Borders(wdBorderVertical)
    .LineStyle = wdLineStyleSingle
    .LineWidth = wdLineWidth050pt
    .Color = wdColorAutomatic
    End With
    .Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
    .Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
    .Borders.Shadow = False
    End With[/vba]

    But I don't see how to edit the dialogs to provide the formatting I want, prolly 'cause I wanna put borders on, not take them off.

    Anybody care to help me figure out how to do that?
    ~Anne Troy

  3. #23
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Okay. I want to set the heading rows on the first row of a table, but all I can find is toggle:

    [vba]Selection.Rows.HeadingFormat = wdToggle[/vba]

    ~Anne Troy

  4. #24
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    The users of this template may sometimes be working with the document already unprotected. How can I make a macro like the following do something like "if protected, unprotect, otherwise...don't unprotect first":

    [vba]Sub SetTblTxt()
    ActiveDocument.Unprotect Password:="password"
    Selection.Style = ActiveDocument.Styles("TableText")
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:="password"
    End Sub
    [/vba]
    ~Anne Troy

  5. #25
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    OK, the easy one fiirst.

    Use True (or False) in place of wdToggle to set, rather than switch, the heading rows.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  6. #26
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Thanks!!
    ~Anne Troy

  7. #27
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    How can I add some error handling? I.e., if the document is protected, "the doc is protect, you gotta unprotect before you can do this", ok/cancel.

    It's yelling at me when I try this:
    [vba]Sub InsTable()
    ' Application.ScreenUpdating = False
    ' ActiveDocument.Unprotect
    If ActiveDocument.Protection = True Then MsgBox ("You must unprotect the document first.")
    Else
    Selection.TypeText Text:=" intable"
    Selection.Range.InsertAutoText
    End If

    End Sub[/vba]

    I know it's something stupid!
    ~Anne Troy

  8. #28
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    I'm trying to answer as quickly as you ask!

    You can use some of the same constants with the dialog that you can with the individual borders, so ...

    [VBA]With Dialogs(wdDialogFormatBordersAndShading)
    .ApplyTo = 3

    .Shadow = False

    .LeftWeight = wdLineWidth050pt
    .LeftStyle = wdLineStyleSingle

    .RightWeight = wdLineWidth050pt
    .RightStyle = wdLineStyleSingle

    .TopWeight = wdLineWidth050pt
    .TopStyle = wdLineStyleSingle

    .BottomWeight = wdLineWidth050pt
    .BottomStyle = wdLineStyleSingle

    .TL2BRStyle = wdLineStyleNone
    .TR2BLStyle = wdLineStyleNone

    .HorizWeight = wdLineWidth050pt
    .HorizStyle = wdLineStyleSingle

    .VertWeight = wdLineWidth050pt
    .VertStyle = wdLineStyleSingle

    .Execute
    End With [/VBA]

    ... will do something. :rofl

    Most of this, however, is not documented and I don't know the values for the ApplyTo (wdTable doesn't seem to work).

    Note, also, that invoking the dialog changes ALL the settings that the dialog can change and there is no simple default value for many of the options - they may reflect the characteristics of the selection, or they may remember what they were last time they were used so you may find you have to explicitly set many or all of them, whereas with the individual property settings you only set the ones you want, so it's a bit of gain on the one hand and loss on the other.

    Good to see the grandson's firmly in charge, by the way.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  9. #29
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    I think you want

    ActiveDocument.ProtectionType
    but I'm not sure of all the values off the top of my head
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  10. #30
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    I also have some code that formats the table at the insertion point. How can I tell it to throw up a message box "you gotta have your cursor in a table first, you dumbass"? if the cursor isn't in a table. Do I just do an On Error thingee? Will that cover it okay?
    ~Anne Troy

  11. #31
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi DB,
    You have to insert a break after "Then" otherwise the If line is regarded as complete (no end if required). The next bit is then being seen as missing a stating "If".



    [VBA]
    Sub InsTable()
    Dim MyAutoText As String
    MyAutoText = "Val" 'Amend as required

    If Not ActiveDocument.ProtectionType = wdNoProtection Then
    MsgBox ("You must unprotect the document first.")
    Else
    Selection.TypeText Text:=" intable"
    NormalTemplate.AutoTextEntries(MyAutoText).Insert Where:=Selection.Range
    End If
    End Sub

    [/VBA]

  12. #32
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    That makes it look for autotext where it doesn't exist?
    I have many autotext entries RIGHT IN the template.
    Do I have to dim every time?
    ~Anne Troy

  13. #33
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Phew. Okay. I've got the IF working right.

    But now, when I run the autotext entry normally, I get what I want.

    When I run it with the macro, I get a space, a paragraph return, and THEN the autotext entry. Anybody know why?
    Here's the code I'm using:

    [vba]Sub InsTable()

    If Not ActiveDocument.ProtectionType = wdNoProtection Then
    MsgBox ("You must unprotect the document first.")
    Else
    Selection.TypeText Text:=" intable"
    Selection.Range.InsertAutoText
    End If
    End Sub[/vba]
    ~Anne Troy

  14. #34
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    OK, we'll go for the easy one first again

    To tell if the cursor is in a table, use

    [VBA]selection.Information (wdWithInTable)[/VBA]

    it returns True or False - I'm sure you can work out which is which - lol
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  15. #35
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Sorry DB,
    I misunderstood your autotext entry (been a long day) . However, I don't get your behavior with your revised coding. The space I understand, but not the paragraph mark. Can you attach your Doc, and I'll see if it replicates here.
    MD

  16. #36
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Okay. I've got this thing sorted, I think. I'll share the code with anybody who wants it, but don't want to put it in the open forum.

    The only problem I have now is that, while I want the toolbar to float, it's smack-dab in the middle of the document window. Any way I can get it to be off to the side or something? I've tried moving it in the template and everything. Doesn't seem to matter much. For the most part, I'm using MD's code for the toolbar--close enough.
    ~Anne Troy

  17. #37
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    A small addition to allow setting of the toolbar position
    Add the following at the head of the code:
    [VBA] Option Explicit
    Private Declare Function GetSystemMetrics Lib "user32.dll" (ByVal nIndex As Long) As Long
    Const SM_CXSCREEN = 0
    Const SM_CYSCREEN = 1

    Function ScrWidth() As Long
    ScrWidth = GetSystemMetrics(SM_CXSCREEN)
    End Function

    Function ScrHeight() As Long
    ScrHeight = GetSystemMetrics(SM_CYSCREEN)
    End Function


    [/VBA]

    Insert the following at the MyBar.Visible line
    [VBA]
    Mybar.Visible = True
    With Mybar
    .Top = ScrHeight * 0.3 'Set fraction as appropriate
    .Left = ScrWidth * 0.3
    End With
    [/VBA]

    You can, if preferred, omit the first code and insert integer positions for the toolbar.

  18. #38
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    You can position a floating command bar with the .Top and .Left properties (possibly combined with the .Width or .Height ones). These are in pixels from the top and left of the screen (not the window) so if you want thm in a non-full screen window you'll need to check the window co-ordinates first (and the screen resolution). For example, running at 1280*1024, this creates a vertical commandbar at the side of a full screen document for me:
    [VBA]
    CommandBars("MyMacros").Left = 1220
    CommandBars("MyMacros").tOP = 160
    CommandBars("MyMacros").Width = 40
    [/VBA]
    Depending on your ultimate requirement you may need to experiment to find what suits you.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  19. #39
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Too cool.
    Worked like a charm.
    I'm marking this one solved.
    ~Anne Troy

  20. #40
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Oops. Didn't even try yours, Tony...
    ~Anne Troy

Posting Permissions

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