PDA

View Full Version : [SLEEPER:] Word 2007 macro to save word as .Docx



mihailovici
02-29-2024, 11:57 AM
Hi, I have this code that saves my word document .docx with a specific name and also converts it to .doc
Do you guys have any idea how i can modify the code so that it saves with docx extension instead of doc and also to delete the original file ?
Thanks
God Bless!


Option Explicit

Sub FPVS()
Dim fisword As String
Dim FOLDER As String
Dim primit As String
Dim cinci As String
Dim cinci1 As String
Dim raport As String
Dim FPVS As String
Dim nrfpvs As String
Dim anfpvs As String
Dim nr As String
Dim MARCA As String
Dim data As String
Dim data1 As String
Dim data2 As String
Dim separate() As String
Dim marca1() As String
Dim pagubit As String
Dim pagubit1() As String
Dim pagubit2 As String
Dim pagubit3 As String
Dim separat1 As String
Dim nume As String
Dim prenume11 As String
Dim pos1 As Integer
Dim pos2 As Integer
Const strDrive As String = "C:\MIHAI\DOC\ASIG\DOSARE"
FPVS = ActiveDocument.BuiltInDocumentProperties("keywords").Value
nr = Replace(Trim(ActiveDocument.BuiltInDocumentProperties("Company").Value), Chr(45), "")
MARCA = ActiveDocument.BuiltInDocumentProperties("Comments").Value
data = ActiveDocument.BuiltInDocumentProperties("Content status").Value
cinci = Right(Replace(Trim(ActiveDocument.BuiltInDocumentProperties("keywords").Value), "/", ".") & Chr(32), 6)
cinci1 = Replace(cinci, " ", "")
separate = Split(FPVS, "/")
nrfpvs = separate(0)
anfpvs = separate(1)
' anfpvs = Right(anfpvs, 2)
marca1 = Split(MARCA, " ")
data1 = Left(data, Len(data) - 4)
data2 = Right(data, Len(data) - 8)
data = data1 & data2
'primit = "FPVS" & " " & nrfpvs & "-" & anfpvs & " " & data & " " & "ecl" & " " & "Mihai"'
fisword = "Rxxx_" & "FPVS" & " " & raport & nrfpvs & "-" & anfpvs & " " & nr & " " & MARCA
FOLDER = "FPVS" & " " & nrfpvs & "-" & anfpvs
' Name strDrive & primit As strDrive & FOLDER
ActiveDocument.SaveAs strDrive & fisword & ".docx"
ActiveDocument.SaveAs FileName:=strDrive & "\" & fisword & ".doc", FileFormat:=wdFormatDocument
' ActiveDocument.ExportAsFixedFormat OutputFileName:=strDrive & fisword & ".pdf", _
' ExportFormat:=wdExportFormatPDF, _
' OpenAfterExport:=False, _
' OptimizeFor:=wdExportOptimizeForPrint, _
' Range:=wdExportAllDocument, From:=1, to:=1, _
' Item:=wdExportDocumentContent, _
' IncludeDocProps:=True, _
' KeepIRM:=True, _
' CreateBookmarks:=wdExportCreateHeadingBookmarks, _
' DocStructureTags:=True, _
' BitmapMissingFonts:=True, _
' UseISO19005_1:=False
' lbl_Exit:
With Application
.ScreenUpdating = False
Loop Through open documents
Do Until .Documents.Count = 0
' Close save
.Documents(1).Close SaveChanges:=wdSaveChanges
Loop
' Quit Word save
.Quit SaveChanges:=wdSaveChanges
End With
Exit Sub
End Sub

Chas Kenyon
02-29-2024, 01:18 PM
If you want a pdf, why are you saving with .docx or .doc extensions?

The following line is saving as .doc:

ActiveDocument.SaveAs FileName:=strDrive & "" & fisword & ".doc", FileFormat:=wdFormatDocument

mihailovici
02-29-2024, 07:39 PM
Hi Chas,
My mistake
I want to save as .docx instead of .doc

Chas Kenyon
03-03-2024, 12:11 PM
Hi Chas,
My mistake
I want to save as .docx instead of .doc

Still:
If you want a pdf, why are you saving with .docx or .doc extensions?

mihailovici
03-12-2024, 11:18 PM
Hi again Chas, my mistake in the thread name

My initial file is a docx
When i save it with a new name it becomes doc,
I want to save it with a new name and with docx extension.

Chas Kenyon
03-13-2024, 10:27 AM
The following line is saving as .doc:

ActiveDocument.SaveAs FileName:=strDrive & "" & fisword & ".doc", FileFormat:=wdFormatDocument

Have you tried .docx instead?

ActiveDocument.SaveAs FileName:=strDrive & "" & fisword & ".docx", FileFormat:=wdFormatDocument

mihailovici
03-19-2024, 05:14 AM
yes, but with no effect :(

jdelano
03-20-2024, 04:11 AM
Why re-invent the wheel? This app will do what you'd like MultiDoc Converter is a Freeware to convert multiple documents between Word, OpenOffice, PDF and many more (multidoc-converter.com) (https://www.multidoc-converter.com/en/index.html) I'd put the .docx files in one folder and have the converted .doc files placed in a new folder. Once the process is finished delete the folder that contains the .docx files.

gmayor
03-22-2024, 08:42 AM
Use instead

ActiveDocument.SaveAs FileName:=strDrive & "" & fisword & ".docx", FileFormat:=wdFormatXMLDocument
FWIW as this thread started by discussing PDF format, note that Word 2007 in its initial release did not include the PDF function. I seem to recall it came with the SP2 update which is still available, later updated to SP3.

mihailovici
04-03-2024, 09:39 AM
Thanks GMayor, I tried replacing the code but with no effect, it exits the word file and keeps the same name. :(