Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #13  
Old 10-05-2017, 09:12 PM
macropod's Avatar
macropod macropod is offline Multiple Files - Printing Windows 7 64bit Multiple Files - Printing Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
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

Try the following revision to the macro. I haven't addressed the sub-folder issue yet; at this stage I'm just focussing on getting all the files in the 'base' folder processed.
Code:
Sub GenerateProjectDocuments()
Application.ScreenUpdating = False
Application.DisplayAlerts = wdAlertsNone
Dim strFolder As String, StrSrc As String, strPath As String, strFile As String
Dim strDocNm As String, wdDoc As Document, FlFmt As Long
strDocNm = ActiveDocument.FullName: strPath = ActiveDocument.Path
strFolder = GetFolder: If strFolder = "" Then Exit Sub
StrSrc = strFolder & "\ProjectDataFile.xlsx"
strFile = Dir(strPath & "\*.doc", vbNormal)
While strFile <> ""
  If strPath & "\" & strFile <> strDocNm Then
    Set wdDoc = Documents.Open(FileName:=strPath & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
    With wdDoc
      FlFmt = .SaveFormat
      If .MailMerge.Fields.Count > 0 Then
        With .MailMerge
          .MainDocumentType = wdNotAMergeDocument
          .MainDocumentType = wdCatalog
          .Destination = wdSendToNewDocument
          .OpenDataSource Name:=StrSrc, ReadOnly:=True, AddToRecentFiles:=False, LinkToSource:=False, _
            Connection:="Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;" & _
            "Data Source=StrSrc;Mode=Read;Extended Properties=""HDR=YES;IMEX=1"";", _
            SQLStatement:="SELECT * FROM `Sheet1$`", SQLStatement1:="", SubType:=wdMergeSubTypeAccess
          .DataSource.ActiveRecord = wdFirstRecord
          .DataSource.LastRecord = .DataSource.ActiveRecord
          .Execute Pause:=False
        End With
        .Close SaveChanges:=False
      End If
    End With
    With ActiveDocument
      .SaveAs2 FileName:=strFolder & "\" & strFile, FileFormat:=FlFmt, AddToRecentFiles:=False
      .Close SaveChanges:=False
    End With
  End If
  strFile = Dir()
Wend
Set wdDoc = Nothing
Application.DisplayAlerts = wdAlertsAll
Application.ScreenUpdating = True
End Sub

Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple Files - Printing Summarise information from multiple worksheets in multiple files alistair_ Excel Programming 5 04-10-2017 08:27 AM
Multiple Files - Printing Printing multiple envelopes in Word 2007 terrydennis Word 4 11-11-2015 05:04 PM
Multiple Files - Printing convert multiple csv files to multiple excel files mit Excel 1 06-14-2011 10:15 AM
Printing multiple page worksheet with watermark zany Excel 2 11-27-2009 01:33 AM
Outlook XP (2002) printing multiple attachments couriced Outlook 0 10-13-2005 05:36 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:19 PM.


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