Consulting

Results 1 to 5 of 5

Thread: Finding working extension of file

  1. #1
    VBAX Regular
    Joined
    Jun 2016
    Posts
    11
    Location

    Question Finding working extension of file

    Hi, I’m just starting my adventure withprogramming and VBA and now I have small problem.
    I try to make a tool to repair documents, and I assumed that files can becorrupted also by having improper extension (done purposely or not),So Ithought I need to find origin extension to repair this. If extension is changedby user by hand, or through opening by improper program, then in my opinion somewherein code should be a sign of extension the file will work properly with.
    Example: first was “doc” file , then somebody changed to xls manuallyso file doesn’t open. I need to find extension that will work – as it was “doc”at the beginning. I don’t know if it’s possible… I thought that if I open filein notepad there is some kind of code in it, and probably part of code may be“origin” extension, but which part? Or is there some other way I could use inVBA? I will be grateful for your response.

  2. #2
    The extension has nothing to do with whether a document is corrupt or not, and will not prevent Word from opening valid documents, whatever the extension is renamed to. The extension is primarily a tool for Windows to identify with which application to associate a particular file type.

    In order to be able to process a document with VBA, you need to be able to open that document. If the document is corrupt, you will not be able to do that even if the extension is correct.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Regular
    Joined
    Jun 2016
    Posts
    11
    Location
    Thank you gmayor for your reply. If I understood correctly, there is no need to takin care of extension. But if it was "doc" and somebody changed it to "dot' it still will open but it will be a template not a document, and user might be working with template instead of document. Or it also desn't matter...?

    Also you wrote:

    Quote Originally Posted by gmayor View Post
    The extension is primarily a tool for Windows to identify with which application to associate a particular file type.

    If the extension is wrong Windows try to open file with wrong application - so it could be considered as coruption. That is why one of options in my tool is checking if the extension
    correct .

    But after all is there somewhere written a code of extension of file? Or way how to get it? Or history of change in extesion?



    Last edited by Dzony; 06-08-2016 at 06:28 AM.

  4. #4
    A Word document doesn't become a Word template because you change its extension. It remains a document. In any case a document may be employed as a template.
    Windows is quite relaxed about extensions. It doesn't impose them. Only one application can have control of a particular extension, so inevitably where the same extension is used by different applications, Windows will always open the application assigned to that extension. That doesn't make it a 'corruption', but a characteristic of the way Windows handles filenames.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  5. #5
    VBAX Regular
    Joined
    Jun 2016
    Posts
    11
    Location
    Ok, got it.
    But if extension of file will be changed from "example.doc" to "example.pdf" Windows will try to open it with pdf application and will fail. User who will not know about change extension before will think that file is corrupted. So I could use a help how to find a way to get proper extension. I can open file by every application I have installed on my computer but maybe there is easier way...

Tags for this Thread

Posting Permissions

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