none
As a new VBA developer I find in the Microsoft Documentation several different formats for saving a document. But I keep getting a compile error. RRS feed

  • Question

  • As a new VBA developer I find in the Microsoft Documentation several different formats for saving a document.  But I keep getting compile errors.

    The general form that I found in the documentation is:

    Documents(NyFile) Save NoPrompt:=True

    This is the way I have used it:

    If count_NewACs Mod file_save_cycle = 0 Then Documents(MasterAC_File)Save NoPrompt:=True 'Save if on cycle

    The variables are dimensioned, and the MasterAC_File has been previously opened and read and written to.

    Any suggestions would be appreciated.


    Lewis D. Eigen

    Tuesday, April 10, 2018 6:41 PM

Answers

  • Hi LDEigen,

    You had mentioned that,"I keep getting compile errors."

    I suggest you to create an object of Document and try to use save method with that object of document to save particular document.

    Below is an example code:

    Sub word_demo()
        Dim objWord As Object
    
        Dim objDoc As Object
    
      
    
        Set objWord = CreateObject("word.Application")
    
        Set objDoc = objWord.Documents.Open("D:\MyFirstSave.docx")
    
        objWord.Visible = True
    
        objDoc.Save
        objDoc.Close savechanges:=True
        objWord.Quit
        Set objWord = Nothing
        Set objDoc = Nothing
        
    End Sub

    Reference:

    Document.Save 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.

    Wednesday, April 11, 2018 2:55 AM
    Moderator