Office 2007 Document contents must match file extension

T

tkibbey

Is there a way to setup Word, Excel or Powerpoint 2007 so that an openxml
file will be opened based on its contents as opposed to the file extension.

For example, if you rename a Word 2003 document from note.doc to note.abc
you can still go to the Word Open menu, select the file and open it.

If you rename a Word 2007 document from note.docx to note.abc you will
receive an error and or the Text encoding File Conversion menu based on how
you attempt to open it.

I'm working with an ongoing scenario where the document extension has been
lost and I don't know whether the extension should be docx, dotx or docm
(also xlsx versus xltx and pptx versus potx) and I would like to avoid
changing the extension multiple times to open the file.

Sincerely,

Tom
 
S

Steve Rindsberg

Tkibbey said:
Is there a way to setup Word, Excel or Powerpoint 2007 so that an openxml
file will be opened based on its contents as opposed to the file extension.

Probably not, and this is by design.

If the extension and the contents don't match, Office 2007 assumes that
somebody's trying to pull a fast one on you and won't open the file.
I'm working with an ongoing scenario where the document extension has been
lost and I don't know whether the extension should be docx, dotx or docm
(also xlsx versus xltx and pptx versus potx) and I would like to avoid
changing the extension multiple times to open the file.

Something like this might help

You'd probably want to extend it to process all the files in a folder, and you
might want to modify the order of the extensions in the sExtensions array, but
it's a start:

Sub ExtendMyName()

Dim sFile As String
Dim sTest As String
Dim x As Long

Dim sExtensions(1 To 5) As String
sExtensions(1) = "PPTX"
sExtensions(2) = "PPTX"
sExtensions(3) = "PPTM"
sExtensions(4) = "POTX"
sExtensions(5) = "PPT"

' Name of file with no extension
sFile = "c:\temp\test"

On Error Resume Next
For x = 1 To UBound(sExtensions)
Name sFile As sFile & "." & sExtensions(x)
Presentations.Open sFile & "." & sExtensions(x)
If Err.Number = 0 Then
' valid extension
Exit For
Else
Name sFile & "." & sExtensions(x) As sFile
End If
Err.Clear

Next

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top