Consulting

Results 1 to 10 of 10

Thread: Word 2007 macro to save word as .Docx

  1. #1

    Word 2007 macro to save word as .Docx

    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 ExplicitSub 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

  2. #2
    VBAX Contributor
    Joined
    Jul 2020
    Location
    Sun Prairie
    Posts
    126
    Location
    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

  3. #3
    Hi Chas,
    My mistake
    I want to save as .docx instead of .doc

  4. #4
    VBAX Contributor
    Joined
    Jul 2020
    Location
    Sun Prairie
    Posts
    126
    Location
    Quote Originally Posted by mihailovici View Post
    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?

  5. #5
    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.

  6. #6
    VBAX Contributor
    Joined
    Jul 2020
    Location
    Sun Prairie
    Posts
    126
    Location
    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

  7. #7
    yes, but with no effect

  8. #8
    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) 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.

  9. #9
    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.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  10. #10
    Thanks GMayor, I tried replacing the code but with no effect, it exits the word file and keeps the same name.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •