Hi,
As you probably realise, the purpose of the test coding is to see if VBA thinks it sees a file of the type which the erroring code line tries to kill ( delete ). The test coding does not appear to see any files of that type, Hence, as we know, the Kill Statement ( https://bettersolutions.com/vba/func...-statement.htm ) will error.
Thanks for the file.
I think I see now some of the information which I was missing: I wrote a few times already that I could not understand why you save the active file with this code line
ActiveDocument.SaveAs strPath & "" & strDocumentName, wdFormatHTML, , , , , True
If you do that code line for when the active file is a very simple file, for example a Word file , MyFile.doc , with just some simple plain text in it, then you get a simple file saved which simply has its name changed to MyFile.htm. At least that was my experience so far: I have only limited experience with these sort of Word / html things
Now I see something for the first time:
I see now that when you do that code line for when the active file is a Word file which contains images, like your 2. KEEP DUPLICATE RECORDS.docx , then you no longer get a simple file saved which simply has its name changed to 2. KEEP DUPLICATE RECORDS.htm
Instead you get a lot of other stuff, including some image files.
So that explains some of the mystery. If you were not aware that this happens, then I am puzzled that you have got this far, and am puzzled that you ever got the macro to work…
If you were aware of this, then you should have told me. If you ask for help on a forum, you should always gives as much information as possible: It’s best to assume the person trying to help you has no idea of what you are doing or wanting to do or how you are attempting to do it.
So , what’s going on….
I lack the experience with these Word and Word VBA issues.
But my initial uneducated guess is that Word will produce different file types when you save with the .htm extension type and that possibly exactly what you get will depend on many factors. This might explain why you get varying results. I don’t really have the experience to help here. I am seeing this phenomena for the first time.
I think I may have heard of that phenomena before, but I can’t recall where and when. This is possibly coming back to my previous point above, that….. my initial uneducated guess is that Word will produce different file types when you save with the .htm extension type and that possibly exactly what you get will depend on many factors. This might explain why you get varying results.
So I am working in Word 2007, and when I run the macro with 2. KEEP DUPLICATE RECORDS.docx active, then the code line ActiveDocument.SaveAs strPath & "" & strDocumentName, wdFormatHTML, , , , , True produces this
2_ KEEP DUPLICATE RECORDS_docx gices these files when saved as _htm.JPG2_ KEEP DUPLICATE RECORDS_docx gives these files when saved as _htm.JPG
Running the complete macro will ( before it errors ) produce this, which I expect is similar to what you have seen:
2_ KEEP DUPLICATE RECORDS_docx gives these files.JPG 2_ KEEP DUPLICATE RECORDS_docx gives these files.JPG 2_ KEEP DUPLICATE RECORDS_docx gives these files when saved as _htm.JPG
Those last 3 screen shots are the same as the previous 2 except that we have also made the directory , MovedToHere , using this code line __ If Dir(strPath & "\MovedToHere", vbDirectory) = "" Then MkDir strPath & "\MovedToHere"
So it all makes sense to me, now. I see where the problem is coming from.
_ No file is produced with the .htm extension, Hence the macro will error if no other files of that type are present.
_ Nothing gets moved to the directory , MovedToHere , because you are looking in the wrong place for those files: The files are in that strange named folder 2-files. ( My Excel is German so Files is translated to Dateien )
I think I probably could re write the macro so that it does what you want, at least here in my Word 2007 version. But it might not work in your system if the code line ActiveDocument.SaveAs strPath & "" & strDocumentName, wdFormatHTML, , , , , True produces slightly different files
I do have many different versions of Word and many different computers. I could probably write a macro and check that it works in all systems. But that would be a lot of work for me which I don’t have the time to do all that just now.
The solution would probably involve looking at all sub folders to make sure we find any files anywhere. Once again this increases the complexity and so increases the work needed.
You might be best advised to try at one of the other forums.
There are lots more people there and you might be lucky to find someone that has tried to do exactly what you are doing , had similar problems, and has an efficient solution already.
I could probably come up with a new solution, but it may not be the best.
( If you get the problem solved at another forum , it would be helpful to tell us about it, for the benefit of anyone else seeing this Thread in the future ).
Otherwise I will take another look at this in a few days when I have some free time
I would also advise that you take some time to understand the current macro, and possibly add your own explaining 'comment notes .
Alan
Bookmarks