0

I have three word doc files and I want to rename them with Now() date. Three files are as

1. EMEA.doc --rename-> EMEA 083117.doc -convert-> EMEA 082317.PDF

2. CEEMEA.doc --rename-> CEEMEA 083117.doc -convert-> CEEMEA 082317.PDF

3. LATAM.doc --rename-> LATAM 083117.doc -convert-> LATAM 082317.PDF

I need to ExportAsFixedFormat(PDF) these .Doc files. Following code do the job for ActiveDocument only. I want to save files in specific location without VBA asking for location.

ActiveDocument.ExportAsFixedFormat OutputFileName:= _
    "C:\Documents and Settings\Administrator\Desktop\EMEA CEEMEA\LATAM.pdf", ExportFormat _
    :=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
    wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
    Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
    CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
    BitmapMissingFonts:=True, UseISO19005_1:=False
VBAbyMBA
  • 806
  • 2
  • 12
  • 30
  • I'm not sure I understand, why don't you just open them one by one in the code and do the same for all of them? Or use a loop? – vacip Aug 23 '17 at 07:35
  • @vacip it take time to open and print and i want to save it. as files in question are just example there are lot of files to rename and convert. – VBAbyMBA Aug 23 '17 at 07:43
  • why don't you do `EMEA.doc -convert-> EMEA 082317.PDF` ? – jsotola Aug 23 '17 at 16:15
  • @jsotola actually I need both files with date `EMEA 082317.doc` and `EMEA 082317.pdf`, and file without date `EMEA.doc` is no use for me. – VBAbyMBA Aug 24 '17 at 06:42

2 Answers2

3

General direction:

  1. You need to tell the program which files you want to manipulate (e.g. "all word files in folder x")
  2. You seem to already have a rule for renaming (file name & " " & date), just loop through all files in question; a batch file might be a good alternative solution to vba for renaming files
  3. Open and save each document to PDF (can be done in background, no need to actually open the document)

Note: You never actually "convert" a word file, only save an additional (PDF) file. To make it look like a "conversion", you need to save the PDF in the same location and delete the original word file.

If you need help with a specifc problem in your program, update your post with the lines of code in question along with a descritpion of the error/wrong behaviour, desired behaviour and what you have tried so far to fix it.

1

Create UserForm for three files and copy the code (Given below) in PDF_Click.

code will Open all three of them one by one and do SAVEAS with Now() date and create PDF for check-marked files using For loop.

Private Sub PDF_Click()

Dim d As String

Finalize.hide
Dim C As MSForms.Control
For Each C In Me.Controls
    If TypeName(C) = "CheckBox" Then
    If C.Value = True Then
    If C.Caption = "Select All" Then
    Else

VD = "C:\Documents and Settings\Administrator\Desktop\EMEA CEEMEA\"

Documents.Open FileName:=VD & C.Caption & ".doc"

d = Format(Now(), "mmddyy")
f = VD & Ctl.Caption & " " & d
ActiveDocument.SaveAs2 f & ".doc"

ActiveDocument.ExportAsFixedFormat OutputFileName:= _
        f & ".pdf", ExportFormat _
        :=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
        wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, TO:=1, _
        Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
        CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
        BitmapMissingFonts:=True, UseISO19005_1:=False

ActiveDocument.Close

    End If
    End If
    End If

Next
End Sub

This answer is open for critics, To improve.