Page 1 of 2 12 LastLast
Results 1 to 15 of 22

Thread: ERROR (Word XP)

  1. #1
    Star Lounger
    Join Date
    Aug 2002
    Location
    Orlando, Florida, USA
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ERROR (Word XP)

    I just want to know how to make a simple caution box pop up if someone in word hits a particular toolbar macro I have setup. If you can help that would be great.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: ERROR (Word XP)

    Can you use the MsgBox function for this? See for instance <post#=165457>post 165457</post#> for a description.

  3. #3
    Star Lounger
    Join Date
    Aug 2002
    Location
    Orlando, Florida, USA
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ERROR (Word XP)

    Well I will use that but let me throw a curve into the equation I need it to attach to the macro that I created with the button on the toolbar. How would I tie the two together?

  4. #4
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ERROR (Word XP)

    Sure, it's pretty simple.

    Sub MacroCalledByToolbarButton()

    MsgBox "You Clicked The Button", vbInformation+vbOkOnly,"Toolbar Macro"

    'The rest of your macro goes here

    End Sub
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: ERROR (Word XP)

    Or:

    <pre>Sub WhateverItIsCalled()
    ' Confirm user wants to do this
    If MsgBox("This macro will change your life. Proceed?", _
    vbExclamation + vbYesNo) = vbNo Then Exit Sub
    ' The real macro follows
    End Sub</pre>

    To give the user an exit.

  6. #6
    Star Lounger
    Join Date
    Aug 2002
    Location
    Orlando, Florida, USA
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ERROR (Word XP)

    So this is what I did:
    I used advice from a few of you and mixed and matched to make my own but guess what it won't work. When I hit the toolbar button nothing happens. Here is the code and the macro that I used and I have tried several different combinations but nothing seems to tie that button in with my msgbox.

    Sub Attachnormal()
    If MsgBox("You are about to delete all styles in ths document",vbcritical+vbOkCancel,"attachnormal")=vb ok Then
    'perform actions for ok
    'Attachnormal Macro
    'Macro recorded 8/22/02 by employee
    With Activedocument
    .UpdateStylesOnOpen = True
    .AttachedTemplate = _
    "C:WindowsApplication DataMicrosoftTemplatesNormal.dot"
    End With
    With ActiveDocument
    .UpdateStylesOnOpen=false
    .AttachedTemplate= "Normal"
    End With
    End If
    Else If
    If Msgbox("You are about to delete all styles in ths document",vbcritical+vbOkCancel,"attachnormal")=vb cancel Then exit sub
    End if
    End Sub

    I tried it without the Else if and it did not work, I tried it with the else if and it did not work. What should I do now. Not quit my day job....

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: ERROR (Word XP)

    I'm afraid that your macro contains several errors, both syntax errors and conceptual errors.

    The lines
    <hr>Else If
    If Msgbox("You are about to delete all styles in ths document",vbcritical+vbOkCancel,"attachnormal")=vb cancel Then exit sub
    End if<hr>
    are incorrect and can be removed without harm.

    Also, it's not clear to me why you attach the Normal template twice.

    And finally, setting UpdateStylesOnOpen to true won't have an effect until the next time you open the document. But since you set it to False again, the styles won't be updated at all.

  8. #8
    Star Lounger
    Join Date
    Aug 2002
    Location
    Orlando, Florida, USA
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ERROR (Word XP)

    Okay I am going to delete those lines. The following was written when I recorded the macro so I am not sure how much control I have over this:
    'Attachnormal Macro
    'Macro recorded 8/22/02 by employee
    With Activedocument
    .UpdateStylesOnOpen = True
    .AttachedTemplate = _
    "C:WindowsApplication DataMicrosoftTemplatesNormal.dot"
    End With
    With ActiveDocument
    .UpdateStylesOnOpen=false
    .AttachedTemplate= "Normal"
    End With

    What I have is a button on my toolbar that is attached to a macro called Attachnormal. When I press that button I want the error box to pop up. It seems simple enough and I know it is something very little I am over looking but what is it?

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: ERROR (Word XP)

    I may not be able to help you here. I still use Word 97. The code you have recorded does only one thing in Word 97: attach the Normal template to the document. It doesn't do anything with the styles in the document. Perhaps it does something to the styles in Word XP, but I don't know anything about that.

    By the way: although recording macros is a good way to get started and to learn a bit about VBA, the code is often not efficient or elegant. For instance, because you selected the Tools/Templates and Add-ins menu option twice, you get two With ... End With blocks. Only one is needed.

    The message box should still pop up, though. I have attached a Word 97 document with a custom toolbar with only one button. It calls the MsgBoxTest macro. this macro puts up a message box and writes a line into the document depending on the button you click. Have a look at the code to see how it works (if it works in XP...)
    Attached Files Attached Files

  10. #10
    Star Lounger
    Join Date
    Aug 2002
    Location
    Orlando, Florida, USA
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ERROR (Word XP)

    I'll try that to. The button does what it is supposed to do and for say you have gone into a document and created various styles well the button (macro) we created will wipe out all those styles and bring back in the Firm standard (normal.dot), this works but I don't get the msg box when I hit the button it just does its thing with no warning. I took out the other with statement and now the button works, but the question is how do you get the button to trigger the msg box. When I test the code and run it in vb editor it works, I get this great msg box, but in real like it doesn't.

  11. #11
    Star Lounger
    Join Date
    Aug 2002
    Location
    Orlando, Florida, USA
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ERROR (Word XP)

    I took out the part of the macro that duplicates itself and the macro works. For the life of me though I cannot get it to work with the button. I have attched the code I am using if you have any more ideas:

    Sub Attachnormal()

    If MsgBox("you are about to delete all styles in this document",vbcritical+vbokcancel,"NewMacros.Attachn ormal")=vbok then

    With ActiveDocument
    .Updatestylesonopen=ture
    .AttachedTemplate=
    "C:windowsapplication datemicrosofttemplatesNormal.dot"
    End With

    End If

    End Sub

    What do you think?

  12. #12
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ERROR (Word XP)

    Maybe we need now to turn our attention to your code that creates the toolbar, the control (button) and assigns the Onaction property to your Attachnormal sub??
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  13. #13
    Star Lounger
    Join Date
    Aug 2002
    Location
    Orlando, Florida, USA
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ERROR (Word XP)

    Yeah but that works it just doesn't call up the button. That code is above as well. It is the With stmt.

  14. #14
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ERROR (Word XP)

    What's the name of your toolbar -- the one with the custom button on it?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  15. #15
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ERROR (Word XP)

    Here's what I recommend:

    Use code to create (and destroy and recreate) your custom toolbar. If you use the Toolbar customize interface, it's too easy to mess up.

    So, here's some working code that creates a custom toolbar that calls "AttachNormal" when the toolbar's only button is clicked:

    Sub CustomBar()
    Dim aBar As CommandBar
    Dim aButton As CommandBarControl
    Dim strToolbarName As String

    strToolbarName = "Custom"

    On Error Resume Next
    Application.CommandBars(strToolbarName).Delete
    On Error GoTo 0

    Set aBar = Application.CommandBars.Add(Name:=strToolbarName, Temporary:=True)
    With aBar
    .Enabled = True 'Make sure it works
    .Position = msoBarTop 'Put it on the top
    .RowIndex = 3 'Put it at the beginning of row 3
    .Protection = msoBarNoProtection 'Allow user to move it around but not change it
    .Visible = True
    End With

    'Create first control (button)
    Set aButton = aBar.Controls.Add(Type:=msoControlButton)
    With aButton
    .Caption = strToolbarName
    .TooltipText = "Your custom error message"
    .OnAction = "AttachNormal"
    .FaceId = 330
    .Priority = 1
    .Visible = True
    .Style = msoButtonIconAndCaption 'Display the image and text
    End With

    Set aButton = Nothing
    Set aBar = Nothing
    End Sub

    Sub AttachNormal()
    If MsgBox("you are about to delete all styles in this document",vbcritical+vbokcancel,"NewMacros.Attachn ormal")=vbok then
    With ActiveDocument
    .Updatestylesonopen=true
    .AttachedTemplate="C:windowsapplication datemicrosofttemplatesNormal.dot"
    End With
    End If
    End Sub

    Paste that code into a Normal.dot code mod and try it out. See if that gets you what you want.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

Page 1 of 2 12 LastLast

Posting Permissions

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