Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-25-2021, 11:58 AM
jotentin jotentin is offline Macro in Word 2007 to make changes and save with another extension Windows 10 Macro in Word 2007 to make changes and save with another extension Office 2007
Novice
Macro in Word 2007 to make changes and save with another extension
 
Join Date: Jun 2021
Posts: 2
jotentin is on a distinguished road
Default Macro in Word 2007 to make changes and save with another extension

Hello.



I have many .doc files and I need to make some changes and save them as .docx.

Always the changes to be made are the same and the name when it is saved must be the one of the active document but with the new extension (docx).

In order to do it, I have created a macro with the macro recorder but although the changes are made correctly, the file is always saved with the name of the file used when I saved the macro (Document1).

The generated code is as follows:

.......... (rest of the code)

ActiveDocument.SaveAs FileName: = _
"Document1.docx", FileFormat: = _
wdFormatDocumentDefault, LockComments: = False, Password: = "", AddToRecentFiles _
: = True, WritePassword: = "", ReadOnlyRecommended: = False, EmbedTrueTypeFonts _
: = False, SaveNativePictureFormat: = False, SaveFormsData: = False, _
SaveAsAOCELetter: = False

Could you please tell me the changes that I must make in the above code in order to save it correctly?

Thanks.
Reply With Quote
  #2  
Old 06-25-2021, 08:51 PM
gmayor's Avatar
gmayor gmayor is offline Macro in Word 2007 to make changes and save with another extension Windows 10 Macro in Word 2007 to make changes and save with another extension Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

If you don't want to retain the original doc file then
Code:
ActiveDocument.Convert
ActiveDocument.Save
If you want to keep the doc file
Code:
Dim oDoc As Document
Dim sName As String
    Set oDoc = ActiveDocument
    sName = ActiveDocument.FullName
    If oDoc.HasVBProject = True Then
        sName = Left(sName, InStrRev(sName, Chr(46))) & "docm"
        oDoc.SaveAs FileName:=sName, _
                    FileFormat:=wdFormatXMLDocumentMacroEnabled
    Else
        sName = Left(sName, InStrRev(sName, Chr(46))) & "docx"
        oDoc.SaveAs FileName:=sName, _
                    FileFormat:=wdFormatXMLDocument
    End If
    Set oDoc = Nothing
You might findDocument Batch Processes useful
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 06-26-2021, 10:33 AM
jotentin jotentin is offline Macro in Word 2007 to make changes and save with another extension Windows 10 Macro in Word 2007 to make changes and save with another extension Office 2007
Novice
Macro in Word 2007 to make changes and save with another extension
 
Join Date: Jun 2021
Posts: 2
jotentin is on a distinguished road
Default

It works perfect for me!
Thanks a lot gmayor.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro in Word 2007 to make changes and save with another extension Macro now requires file extension entered to open document Rampum15 Word VBA 2 12-09-2019 06:19 AM
Macro in Word 2007 to make changes and save with another extension Macro to save Word 2007 document using info from Quick Parts staicumihai Word VBA 2 08-08-2018 01:21 AM
Cant save document as docx or doc using macro in Word 2007 staicumihai Word VBA 1 04-27-2018 10:59 AM
Macro in Word 2007 to make changes and save with another extension How To Apply A VBA Macro to All Subfolders in a Directory of a docx. Extension jc491 Word VBA 8 09-11-2015 08:31 AM
How can I save a macro in the PowerPoint 2007 default presentation mrayncrental PowerPoint 1 06-09-2014 06:13 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:50 PM.


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