activeworkbook.save error

  • Hi folks,
    I am stumped.
    I have a workbook that has been working fine for many months and has now thrown up an error.
    The situation is that a userform opens a central file and saves a new record/updates an existing record then saves the file.
    The file path/name is hard coded into the VBA.
    The error is that even though the file opened is correct and the data copied over is correct, when I come to the activeworkbook.save line, it defaults to saving the file into my documents.


    Has anyone ever encountered this issue?


    I thought it was a variable that needed setting to nothing however this has not solved the issue.



    All help gratefully appreciated.


    Cheers


    Dave

  • Re: activeworkbook.save error


    Try this instead:


    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • Re: activeworkbook.save error


    Hi Rory,
    Many thanks.
    Is it just using the wb and the with section that makes the difference?
    I am rather hoping to understand why my code caused an issue?


    Dave

  • Re: activeworkbook.save error


    Code
    Do While Not IsEmpty(.Cells(n, "A")) And n < .Rows.Count


    Rory, the above line gives me an application defined or object defined error.


    I can't see that n is ever assigned anything before it is called as a variable. Could this be the issue?


    Dave

  • Re: activeworkbook.save error


    Yes - sorry, I omitted the line


    Code
    n = 4


    before that loop!!

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • Re: activeworkbook.save error


    Hi it is still not saving into the open file. It saves a default version into my documents.
    This is so weird. There is no reference to my documents in any of the code.
    Sadly I am not able to paste the entire wb as the data can't go outside my office.
    Thanks' for your help.


    Dave

  • Re: activeworkbook.save error


    Ok the fix is - the file opened as read only for some reason - until 3 days ago it wasn't opening as read only. Save the file as a new name - update the name in the code. Sorted.


    Dave

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!