View Single Post
 
Old 07-15-2014, 01:08 AM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,375
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

Why do the dotx files need to be opened? Or are you creating new documents based on them - an entirely different proposition?

For an active document, updating links can be as simple as:
ActiveDocument.Fields.Update

Silently saving a file merely requires the use of the SaveAs2 method. For example:
Code:
    With ActiveDocument
      .SaveAs2 FileName:=StrPth & StrNm & ".pdf", FileFormat:=wdFormatPDF, AddToRecentFiles:=False
      .Close SaveChanges:=False
    End With
where StrPth & StrNm represent the path & name, respectively. If you precede that with a Dir test for the presence of the files, you can invoke that process or the dialogue, as the case requires - or you can skip the test and simply let the macro overwrite any existing files. StrPth can be pre-coded or captured from the FileOpen dialogue. For example:
Code:
Sub Demo()
Dim i As Long, StrPth As String, StrNm As String, wdDoc As Document
With Application.FileDialog(msoFileDialogOpen)
  .AllowMultiSelect = True
  If .Show = -1 Then
    StrPth = Left(.SelectedItems(1), InStrRev(.SelectedItems(1), "\"))
    'Process each document
    For i = 1 To .SelectedItems.Count
      Set wdDoc = Documents.Open(FileName:=.SelectedItems(i), ReadOnly:=True, AddToRecentFiles:=False)
      With wdDoc
        .Fields.Update
        StrNm = .Bookmarks("docnumber").Range.Text & _
          .Bookmarks("doctype ").Range.Text & _
          .Bookmarks("sitename").Range.Text & _
          .Bookmarks("personname").Range.Text
        .BuiltInDocumentProperties("Title") = StrNm
        'Do your processing of the opened document here
        .SaveAs2 FileName:=StrPth & StrNm & ".pdf", FileFormat:=wdFormatPDF, AddToRecentFiles:=False
        .Close SaveChanges:=False
      End With
    Next
  End If
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote