Public
Sub
search()
Dim
StrDatei
As
String
Dim
I
As
Integer
Dim
StrTyp
As
String
Dim
Dateiname
As
String
Dim
Zeit
As
Date
strVerzeichnis = "C:\Users\Oli\Downloads\"
StrTyp =
"*.csv"
Dateiname = Dir(strVerzeichnis & StrTyp)
Dateiname_neu = Dateiname
Zeit = 0
Do
While
Dateiname <>
""
If
Zeit > FileDateTime(strVerzeichnis & Dateiname)
Then
Zeit = FileDateTime(strVerzeichnis & Dateiname)
Dateiname_neu = Dateiname
End
If
Dateiname = Dir
Loop
GesuchteDatei = strVerzeichnis & Dateiname_neu
Call
import
End
Sub
Public
Sub
import()
With
ActiveDocument.MailMerge
.MainDocumentType = wdCatalog
.OpenDataSource Name:=GesuchteDatei, _
ReadOnly
:=
True
, _
Connection:=
"Sales"
End
With
If
ActiveDocument.MailMerge.State = wdMainAndDataSource
Then
ActiveDocument.MailMerge.Execute
End
If
ActiveDocument.Application.WindowState = wdWindowStateMinimize
If
MsgBox(
"Serienbrief Drucken ?"
, vbYesNo + vbQuestion, _
"Serienbrief-Erstellung - Drucken - Seitenvorschau"
) = vbYes
Then
ActiveDocument.Application.WindowState = wdWindowStateMaximize
savEnvAlert = Application.DisplayAlerts
savEnvBackground = Options.PrintBackground
Application.DisplayAlerts = wdAlertsNone
Options.PrintBackground =
False
ActiveDocument.PrintOut
Application.DisplayAlerts = savEnvAlert
Options.PrintBackground = savEnvBackground
End
If
End
Sub