none
Disable SaveAs from Access RRS feed

  • Question

  • I open a Word doc from Access VBA through Automation. I need to disable only the SaveAs in the opened doc from Access VBA code.

    thanks

    Monday, December 19, 2016 5:32 PM

Answers

  • Hi nonlinearly,

    you had mentioned that,"I have already saved the opened doc in a predefined path. So if I disable the SaveAs then every time the user Save the doc the doc will be saved in this predetermined path only without a choice to change it using SaveAs."

    I think you have some misunderstanding.

    first of all you can't disable the "SaveAs".

    you had mentioned that "you already saved the opened document"

    if you had already saved that then "SaveAs" will not occur again.

    it will occur only first time when you did not save it.

    after doing the SaveAs first time, after that only "save" will be call. so if you try to close the document without saving then it will show you a confirmation box that you sure want to close the document without saving the changes you had done.

    you can see that in your code you are using "Documents.Add"

    so you are creating the new document every time.

    if you want to save the current document at predefine location and the document is already available the try to use "Documents.open". with the help of that you can open the document from that location and again after making some changes you can save it and close it.

    so if you do like this then "SaveAs" will not occur.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by nonlinearly Wednesday, December 21, 2016 1:52 PM
    Wednesday, December 21, 2016 5:04 AM
    Moderator

All replies

  • Hi nonlinearly,

    it looks like when you are trying to close the document without saving at that time it is displaying you a SaveAs dialog.

    so you want to suppress that SaveAs dialog.

    If you are trying to close the document by user interface then there is no way to suppress it. it will show the dialog whenever you try to close the document without saving.

    but if you are trying to close the document using VBA code then you can use below line of code.

    SaveChanges:=wdDoNotSaveChanges

    Example:

    Sub demo()
    Dim objWord As Word.Application
    Dim doc As Word.Document
    Set objWord = CreateObject("Word.Application")
    With objWord
        .Visible = True
        Set doc = .Documents.Add
    End With
    With objWord.Selection
      .TypeText "Demo Text"
      .TypeParagraph
    End With
    objWord.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
    objWord.Quit
    Set objWord = Nothing
    End Sub
    

    in the above example it will create a new word document. add some text in it. then it will close the document without saving it.

    Reference:

    Window.Close Method (Word)

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, December 20, 2016 12:31 AM
    Moderator
  • Hi, thank you for your response,

    I forget to say that I have already saved the opened doc in a predefined path. So if I disable the SaveAs then every time the user Save the doc the doc will be saved in this predetermined path only without a choice to change it using SaveAs.

    This is the code:

    Private Sub CreateNewDoc(path) Dim objWord As Word.Application Dim doc As Word.Document Set objWord = CreateObject("Word.Application") Set doc = objWord.Documents.Add doc.SaveAs path

    doc.Visible=True doc.Activate End Sub





    • Edited by nonlinearly Tuesday, December 20, 2016 9:30 AM
    Tuesday, December 20, 2016 9:13 AM
  • Hi nonlinearly,

    you had mentioned that,"I have already saved the opened doc in a predefined path. So if I disable the SaveAs then every time the user Save the doc the doc will be saved in this predetermined path only without a choice to change it using SaveAs."

    I think you have some misunderstanding.

    first of all you can't disable the "SaveAs".

    you had mentioned that "you already saved the opened document"

    if you had already saved that then "SaveAs" will not occur again.

    it will occur only first time when you did not save it.

    after doing the SaveAs first time, after that only "save" will be call. so if you try to close the document without saving then it will show you a confirmation box that you sure want to close the document without saving the changes you had done.

    you can see that in your code you are using "Documents.Add"

    so you are creating the new document every time.

    if you want to save the current document at predefine location and the document is already available the try to use "Documents.open". with the help of that you can open the document from that location and again after making some changes you can save it and close it.

    so if you do like this then "SaveAs" will not occur.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by nonlinearly Wednesday, December 21, 2016 1:52 PM
    Wednesday, December 21, 2016 5:04 AM
    Moderator
  • I do not want user to go to File-->SaveAs but as you said: first of all you can't disable the "SaveAs"...

    Thanks I thought that it could be...

    Wednesday, December 21, 2016 1:52 PM
  • Hi nonlinearly,

    you can't disable "save as" but you can try to hide the Save As button.

    please refer the code mentioned below.

    <?xml version="1.0" encoding="UTF-8"?>  
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">  
    <commands>  
    <command idMso="FileSaveAs" enabled="false"/>  
    <command idMso="FileSave" enabled="false"/>  
    </commands>  
    </customUI>  
    

    Reference:

    How to disable the "save" and "save as" buttons in Office

    you can also try to use "Custom UI Editor for Microsoft Office" to add xml code.

    Reference:

    Customize the Word Ribbon User Interface

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, December 22, 2016 6:03 AM
    Moderator
  • Hmmm... Maybe this is what I want but how can I do it from Access using Ms Word Automation?

    • Edited by nonlinearly Friday, December 23, 2016 8:09 AM
    Friday, December 23, 2016 8:09 AM
  • Hi nonlinearly,

    xml file stored with document it self.

    so to make changes in ribbon we need to access the document.

    we can use "Custom UI Editor for Microsoft Office" to add or modify the xml file.

    so here I am afraid it is not possible for you to modify it from access.

    also it creates xml files for each document.

    so if there are multiple documents and you think that changes made one time will work for all the documents then no, it will not work like that. you have to hide the button in every document.

    I think it's not a suitable way for you.

    so you need to think about work around that can help you to solve your issue.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, December 26, 2016 5:25 AM
    Moderator
  • Nonlinearly,

    In your CreateNewDoc it should be possible to use a template for the new document in which you have changed the xml as Deepak mentioned.

    Set doc = objWord.Documents.Add YourTemplate

    Then the suppression of the SaveAs button will be realised in every new document based on this template.

    Jan

    Tuesday, December 27, 2016 9:37 AM