PDA

View Full Version : Solved: Word 2003 VBA SaveAs file - need help!



megha
01-24-2012, 01:04 PM
Currently the button on my file called "Final Save" to SaveAs the file working fine. I would like add a code to second button for temporary save purpose where i can modify my file as many times as i want and as i click the temporary save button it should keep deleting the old verison of the file and always keep only one latest one and finally when i click final save button it delete temporary file from temp folder and SaveAs the final version to completed folder.

megha
01-25-2012, 07:56 AM
no help? :(

I am looking for a code where i can saveas the word document then can modify the same file as many times as i want and as i continue (for example if i saveas for 1st time that will be version 1 then i modify it that will be version 2 at that time version 1 get deleted autometically then if i modify it again means for 3rd time then version 2 get deleted and the last one stay in the folder) any help??? i would appreciate.

megha
01-25-2012, 02:23 PM
Ok i have give it a try and hoping to get help. I have three buttons on the file.

1)First button to create a checklist, works fine.
2)Second button to modify the created checklist from above step (step 1) and here it's creating a problem. When i click the second button (Modify File) the error message came up stating "file not found" and when i click debug it highlight "(Kill dPath & dFileName)". I know it's because i have current date and time as a file name so macro cannot find anything to delete but create second file.

can someone please help me to auto delete the first file when second added? I will work on third (final save) button later by myself but for now i really need help with my second button (modify file). A waiting for someone reply.!!!

fumei
01-25-2012, 08:58 PM
1. It is a really good idea to use Option Explicit.

2. the problem is with:

sFileName = sFileName & ".doc"
dFileName = sFileName & ".doc"


sFileName = Jan_25_2012__07_25_09_PM.doc
dFileName = Jan_25_2012__07_25_09_PM.doc.doc

Notice the doubled up .doc? Nope...there is no such file.

fumei
01-25-2012, 11:49 PM
BTW, whenever there is a File not found error it is because of one of two reasons.

1. the file is not there (deleted or in a different location)

2. the string of the filename is wrong.

In this case it is #2.

As a good debugging tool, when you get this error place the cursor over the variable - the name of the file that is making the error. The value is displayed, and in this case it shows the double .doc.

megha
01-26-2012, 09:55 AM
Thank you, Fumei!

I made little change to avoid double .doc then run a test and now it says "Run-time error 70: Permission denied" what does this mean? I can delete the file/folder manually from that same location.

You've advised to use "Option Explicit" but i have no idea about it as i am not good with the macro. i am actually a beginner. I would really appriciate any help.

Thank you...!!