DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Vba\word

  1. #1
    Join Date
    Feb 2008
    Posts
    8

    Vba\word

    I created a macro and added it to the toolbar. Inside the macro, it toggles the button on the toolbar. When I close out word, it prompts to save the .dot file if I click the macro button that I added. I believe it is doing this because I am toggling the button inside the macro. Is there a way to keep it from prompting the save of the .dot file? Here is my macro.
    Code:
    Sub MarkAsCrit()
    Dim Answer
    Dim initValue
    
    Dim controlIndex
    controlIndex = 1
    Do While (controlIndex < CommandBars("standard").Controls.Count And _
        CommandBars("standard").Controls(controlIndex).Caption <> "TemplateProject.Module1.MarkAsCrit")
        controlIndex = controlIndex + 1
    Loop
    
    On Error Resume Next
    initValue = ActiveDocument.Variables("CRIT").Value
    If initValue = "YES" Then
        Answer = MsgBox("Are you sure you want to UNMARK this as critical?", vbYesNo, "Save Document")
        If Answer <> vbCancel Then
            If Answer = vbYes Then
                ActiveDocument.Variables("CRIT").Delete
                ActiveDocument.Variables.Add "CRIT", "NO"
                If (controlIndex < CommandBars("standard").Controls.Count) Then
                    CommandBars("standard").Controls(controlIndex).TooltipText = "Mark critical"
                    CommandBars("standard").Controls(controlIndex).State = msoButtonUp
                End If
            Else
                ActiveDocument.Variables("CRIT").Delete
                ActiveDocument.Variables.Add "CRIT", "YES"
            End If
        End If
    Else
        Answer = MsgBox("Are you sure you want to MARK this as critical?", vbYesNo, "Save Document")
        If Answer <> vbCancel Then
            If Answer = vbYes Then
                ActiveDocument.Variables("CRIT").Delete
                ActiveDocument.Variables.Add "CRIT", "YES"
                If (controlIndex < CommandBars("standard").Controls.Count) Then
                     CommandBars("standard").Controls(controlIndex).TooltipText = "Unmark critical"
                    CommandBars("standard").Controls(controlIndex).State = msoButtonDown
                End If
            Else
                ActiveDocument.Variables("CRIT").Delete
                ActiveDocument.Variables.Add "CRIT", "NO"
            End If
        End If
    End If
    
    End Sub
    Last edited by Hack; 02-14-2008 at 12:53 PM. Reason: Added Code Tags

  2. #2
    Join Date
    Dec 2003
    Location
    San Diego
    Posts
    202
    I believe, if you are adding or changing the button only for that spreadsheet, then it will always ask you if you want to save the template, because you have changed it. Try adding the button to the application, and not the individual workbook. Also, if this is a template you are working on, maybe you should prompt the user to save the Workbook before updating it.

    Good luck,
    Michael Sanchez
    Managing Technical Editor
    Forum Moderator
    FreeVBCode.com

  3. #3
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,663
    And it if it a template, then you would want to force a SaveAs so the user would have to give it a new name, thus preserving the template for later use.

  4. #4
    Join Date
    Feb 2008
    Posts
    8

    vba\word

    I never want to save the template. Basically, what I am doing is storing a bunch of word documents out on the network with information about the documents stored in the database. When I pull the document off of the network for the user to edit, I also pull the template off of the network, and I embed the template with macros that are attached to buttons into the document. The buttons allow the user to tell the system various things like the document is completed. When the document is closed, the template is stripped out and the document is saved back to the network, the word document and the .dot file are deleted off of the local machine, and the database is updated.

    I want to be able to do this without the user being prompted to save the .dot file.

  5. #5
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,663
    Try: DisplayAlerts = wdAlertsNone

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center