Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-13-2022, 08:59 AM
Rampum15 Rampum15 is offline I need to edit a macro to open *.Doc and *.Docx files Windows 10 I need to edit a macro to open *.Doc and *.Docx files Office 2019
Novice
I need to edit a macro to open *.Doc and *.Docx files
 
Join Date: Dec 2019
Posts: 8
Rampum15 is on a distinguished road
Default

Hi Paul,


Thank you very much, I appreciate your information! However, I don't want to sound ungrateful, but I'm not looking to change what we're doing or how we do it. 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. If that isn't possible, then I will convert all of our files to the new *.docx extension, and modify the macro accordingly.

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. Do you have a macro that will actually convert the files similar to how the Open/Save As function works?

Again, thank you for your help!
Reply With Quote
  #2  
Old 09-13-2022, 04:16 PM
macropod's Avatar
macropod macropod is offline I need to edit a macro to open *.Doc and *.Docx files Windows 10 I need to edit a macro to open *.Doc and *.Docx files Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,489
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by Rampum15 View Post
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 View Post
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 View Post
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 View Post
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.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot open files created in Word/show up as DOCX Alcore Office 4 10-24-2021 02:08 AM
I need to edit a macro to open *.Doc and *.Docx files View and edit docx files in Word 2003 orealius Word 4 03-16-2019 08:11 AM
I need to edit a macro to open *.Doc and *.Docx files I cannot open .docx files even though I have MS Office 2016 syeh11 Word 1 09-14-2015 10:16 PM
How to open Docx files? mond_bees Word 12 08-29-2012 03:32 AM
Office 2007 will not open .docx files Reg1987 Word 1 12-15-2010 11:55 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:25 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft