Quote:
Originally Posted by Rampum15
I'm not looking to change what we're doing or how we do it.
|
From an end-user perspective, the approach I proposed is the same as you're already using.
Quote:
Originally Posted by Rampum15
All I really need to know is if there is a way to edit our current macro so that it opens word documents regardless of their extension.
|
It is not possible to open an individual file without supplying the correct extension.
Quote:
Originally Posted by Rampum15
If that isn't possible, then I will convert all of our files to the new *.docx extension, and modify the macro accordingly.
|
Converting .doc files with macros to the docx format will delete those macros. Still, if that's what you want:
Code:
Sub CnvtDocsToDocx()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, strDocNm As String, wdDoc As Document
strDocNm = ActiveDocument.FullName
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.doc", vbNormal)
Do While strFile <> ""
If strFolder & "\" & strFile <> strDocNm Then
If UBound(Split(strDocNm, ".doc")) = 0 Then
Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
With wdDoc
'If .HasVBProject = True Then
'.SaveAs2 FileName:=.FullName & "m", FileFormat:=wdFormatXMLDocumentMacroEnabled, AddToRecentFiles:=False
'Else
.SaveAs2 FileName:=.FullName & "x", FileFormat:=wdFormatXMLDocument, AddToRecentFiles:=False
'End If
.Close SaveChanges:=False
End With
Kill strFolder & "\" & strFile
End If
End If
strFile = Dir()
Loop
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub
Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
The commented-out lines, if un-commented, will save doc files containing macros in the required docm format. Of course, you'll then also have to modify the calling code to reference the correct extension to open the document...
Quote:
Originally Posted by Rampum15
Speaking of converting files, I've tried a couple of macros online, but they just change the extension so the files open in compatibility mode.
|
No, that is not what the macro does
at all. The macro converts the files into actual Word templates, changing the extension is just part of that. You will notice, for example, that double-clicking on any of those templates will not open them but instead opens a new document with the same appearance but named Document1, Document2, etc., instead of the template's name. That is also why I said you would need to change your code from Documents.Open to Documents.Add, so the actual template doesn't get opened for editing.