Consulting

Results 1 to 6 of 6

Thread: Solved: Save changes to Add-in on application close

  1. #1

    Solved: Save changes to Add-in on application close

    I have an add-in with content that can be modified via a userform. The problem is, the changes aren't being saved. How can I save the add-in whenever Excel closes? Thanks very much,
    Gabe

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,089
    Location
    A quick search of the net comes up with this answer;

    http://www.bettersolutions.com/excel...U822216331.htm.

    Saving your changes.

    When you make changes to a workbook and try and close it, you are prompted to save your changes.

    If you make any changes to your code in an Excel add-in, you will not be prompted to save the changes. You must manually save the changes before closing.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You should not use the addin to persist your data, you should use some other method, such as a textfile, an INI file, the registry and so on.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    VBAX Mentor anandbohra's Avatar
    Joined
    May 2007
    Location
    Mumbai
    Posts
    313
    Location
    Quote Originally Posted by gabethegrape
    I have an add-in with content that can be modified via a userform. The problem is, the changes aren't being saved. How can I save the add-in whenever Excel closes? Thanks very much,
    Gabe
    Write this code in Thisworkbook of your Addin
    [VBA]Private Sub Workbook_BeforeClose(Cancel As Boolean)
    ThisWorkbook.Save
    End Sub[/VBA]
    Always Mark your Thread as Solved the moment u got acceptable reply (located under Thread tools)
    Practice this & save time of others in thinking for unsolved thread

  5. #5
    Thanks for the reply. That works well. XLD, how would I go about saving my data to a text file? What's the advantage of doing it this way over saving the changes directly in the add-in? I noticed when I added the code to save the add-in before close that excel stalls a bit. Is this one of the disadvantages? Would it do this if I stored the data in a text file or an INI?

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    It is not a good practice to keep the data and the logic in the same workbook, it creates unnecessary complexities. Far better to separate them, so that the logic goes in the addin, and the data goes in some sort of data repository, whatever you choose for trhat.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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