none
Word SaveAsDialog Save button doesn't work RRS feed

  • Question

  • I've inherited some vba code in a template that is used as an addin, if I have my terminology right - I don't know much about this stuff.  The code takes over the Word Save & SaveAs function and displays the SaveAsDialog as needed.  However, in certain situations (that I'll describe in a moment), clicking on the save button on that dialog results in nothing happening.  The dialog doesn't close, no other prompt appears and the document is not saved no matter how many times the buttons is clicked.

    This happens with the following VBA code:

       With UserSaveDialog
                SavePath = ActiveDocument.Path + "\" + ActiveDocument.Name
                .Name = SavePath
                If .Display Then
                    .Execute
                End If
            End With

    Where the document exists already and the dialog box opens in the correct folder with the correct document name filled in.

    I'm using Word 2010. This problem doesn't occur with 2003.  And I should note that if I load the document manually, through word and then check the addin to activate it, then the code works OK.

    The problem occurs when the document is opened through a VB.NET program.  The code had been in VB6, but I converted it.  That code is below:

                     v10Word = CreateObject("Word.Application")
    
                     'Set the instance to the event handler
                    v10Word.AddIns.Add(FileName:=fPrompt.AddInPath, Install:=True)
     
                    'Open Existing document
                    v10Word.Documents.Open(FileName:=fPrompt.DocToPrint, ConfirmConversions:=False, _
                    ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
                    PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
                    WritePasswordTemplate:="", Format:=Word.WdOpenFormat.wdOpenFormatAuto)
    
                    'Open the data source
     		v10Word.ActiveDocument.MailMerge.OpenDataSource(Name:= _
                    fPrompt.ExcelPath, ConfirmConversions:=False, ReadOnly:= _
                    False, LinkToSource:=True, AddToRecentFiles:=False, PasswordDocument:="", _
                     PasswordTemplate:="", WritePasswordDocument:="", WritePasswordTemplate:= _
                    "", Revert:=False, Format:=Word.WdOpenFormat.wdOpenFormatAuto, Connection:=MergeFileConStrHdrNo _
                    , SQLStatement:="SELECT * FROM `MergeFile$`", SQLStatement1:="", SubType _
                    :=Word.WdMergeSubType.wdMergeSubTypeAccess)
    
                    'Remove document protection if necessary
                    WrkProtect = v10Word.ActiveDocument.ProtectionType
                    If v10Word.ActiveDocument.ProtectionType <> Word.WdProtectionType.wdNoProtection Then
                        v10Word.ActiveDocument.Unprotect()
                    End If
    
                    'Protect the new document if the original was protected
                    If WrkProtect <> Word.WdProtectionType.wdNoProtection Then
                        With v10Word.ActiveDocument
                            .FormFields.Shaded = True
                            .Protect(Type:=WrkProtect, NoReset:=True)
                        End With
                    End If
     
                    DocName = v10Word.ActiveDocument.Name
                    v10Word.WindowState = Word.WdWindowState.wdWindowStateNormal
                    v10Word.Visible = True
    

    I've tried skipping any one of these blocks of code at a time with no effect. I should mention that this code is designed to allow users to open existing documents that were created via word merge or the templates used to create the merged documents.

    I've been banging my head against the wall with this all week with no luck.  I'd really appreciate any ideas.  (I did see one suggestion on this forum that providing the UNC path might help and at first it seemed to, but then I discovered that the real difference is that if I give the SaveDialog Name property a path other than the one the document is in, then the save will occur, but then it prompts to overwrite the existing file.)

    Thank you!

    Wednesday, August 14, 2013 7:00 PM

Answers

  • I stumbled onto the answer.  I was told by someone more familiar with the project than I, that I had to open a new document and load my addon as a global template (without activating it), which I did.  But my VB code adds it so I suppose it was running twice or something.  When I removed the addin from the  global templates, it fixed the problem.


    • Marked as answer by JohnDMCDMC Friday, August 16, 2013 3:26 PM
    • Edited by JohnDMCDMC Friday, August 16, 2013 3:27 PM
    Friday, August 16, 2013 3:26 PM