1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
| Public Sub Document_Open() 'Acties bij het openen van het document
'-------- STARTEN VAN DE MACRO ------------------------------------------------------------------------------
Application.ScreenUpdating = False
'------ KOPPELING MAKEN MET ACTIVE DIRECTORY -----------------------------------------------------------------------------
On Error Resume Next
'Defineer de velden tbv Active Directory
Dim strGivenName As String
Dim strMiddleName As String
Dim strLastName As String
Dim strInitials As String
Dim strTelephoneNumber As String
Dim strHomePhone As String
Dim strMobileNumber As String
Dim strFaxNumber As String
Dim strEmail As String
'Maak de koppeling met Active Directory
Set objSysInfo = CreateObject("ADSystemInfo")
strUserDN = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUserDN)
'Vul de velden vanuit Active Directory
strGivenName = objUser.Get("givenName") 'voornaam
strLastName = objUser.Get("sn") 'achternaam
strMiddleName = objUser.Get("middlename") 'tussenvoegsel
strInitials = objUser.Get("initials") 'initialen
strTelephoneNumber = objUser.Get("telephoneNumber") 'telefoonnummer werk
strHomePhone = objUser.Get("homePhone") 'telefoonnummer thuis
strMobileNumber = objUser.Get("mobile") 'mobiel nummer
strFaxNumber = objUser.Get("facsimileTelephoneNumber") 'fax nummer werk
strEmail = objUser.Get("mail") 'emailadres
'------ USERFORM / invulscherm --------------------------------------------------------------------------------------------------
'Open de Userform
Load Userform1
'Vul het Userform met de velden van Active Direcory
'Zet puntjes tussen de initialen als er nog geen puntjes staan
If InStr(strInitials, ".") = 0 Then 'Als er nog geen puntjes in de Initialen staan dan
strInitials = Replace(strInitials, "A", "A.")
strInitials = Replace(strInitials, "B", "B.")
strInitials = Replace(strInitials, "C", "C.")
strInitials = Replace(strInitials, "D", "D.")
strInitials = Replace(strInitials, "E", "E.")
strInitials = Replace(strInitials, "F", "F.")
strInitials = Replace(strInitials, "G", "G.")
strInitials = Replace(strInitials, "H", "H.")
strInitials = Replace(strInitials, "I", "I.")
strInitials = Replace(strInitials, "J", "J.")
strInitials = Replace(strInitials, "K", "K.")
strInitials = Replace(strInitials, "L", "L.")
strInitials = Replace(strInitials, "M", "M.")
strInitials = Replace(strInitials, "O", "O.")
strInitials = Replace(strInitials, "N", "N.")
strInitials = Replace(strInitials, "P", "P.")
strInitials = Replace(strInitials, "Q", "Q.")
strInitials = Replace(strInitials, "R", "R.")
strInitials = Replace(strInitials, "S", "S.")
strInitials = Replace(strInitials, "T", "T.")
strInitials = Replace(strInitials, "U", "U.")
strInitials = Replace(strInitials, "V", "V.")
strInitials = Replace(strInitials, "W", "W.")
strInitials = Replace(strInitials, "X", "X.")
strInitials = Replace(strInitials, "Y", "Y.")
strInitials = Replace(strInitials, "Z", "Z.")
End If
'Vul het Userform met de velden vanuit Active Directory
If strMiddleName = "" Then Userform1.txtBehandeldDoor.Value = strInitials + " " + strLastName
If strMiddleName <> "" Then Userform1.txtBehandeldDoor.Value = strInitials + " " + strMiddleName + " " + strLastName
Userform1.txtTelefoonnummer.Value = strTelephoneNumber
Userform1.txtNaamTekenbevoegde.Value = Userform1.txtBehandeldDoor.Value
'Vul de Userform met vaste waarden
Userform1.txt1Slotzin.Value = "Wij vertrouwen erop u voldoende te hebben geïnformeerd."
Userform1.txt2Slotzin.Value = "Mocht u hierover vragen of opmerkingen hebben, dan kunt u contact opnemen met " + Userform1.txtBehandeldDoor.Value + ", telefoonnummer " + Userform1.txtTelefoonnummer.Value + "."
Userform1.txt1Afsluiting.Value = "Met vriendelijke groet"
Userform1.txt2Afsluiting.Value = "Hoogachtend"
Userform1.txtBijlagenAantal = "0"
Userform1.txtCc = "-"
Userform1.txtDatumVandaag = Format(Date, "D MMMM YYYY") 'Datum vandaag (dag maand jaar)
Userform1.txtOnzeReferentie = Format(Date, "YYYYMMDD") & " " & Format(Time, "hhmmss") 'Onze referentie (jaar maand dag uur minuut seconde)
'Laat het userform zien
Userform1.Show
'klik op de knop "OK" bij formulieren \ userform1 \ op de code bij het userform te zien.
'Windows(sBrondocument).Activate 'Activeer het brondocument zodat de macro na 'Application.OnTime' weer opgestart kan worden
Windows("Brief (Compatibiliteitsmodus)").Activate
Application.OnTime when:=Now + TimeValue("00:00:01"), Name:="BouwpartnerToevoegen" 'ga naar sub BouwpartnerToevoegen
End Sub
'------ KOPPELING MAKEN MET MAILMERGE (Bouwpartner sheet) -------------------------------------------------------------------
Public Sub BouwpartnerToevoegen()
'Vul de velden in
strActivePad = ActiveDocument.Path 'pad naar de Betreffende Project / standaarddoc
sFolder = "\Algemeen" 'tbv pad naar de bouwpartnersheet
sNewPath = CreateNewPath(strActivePad, sFolder) 'pad naar de bouwpartnersheet
sBrondocument = ActiveDocument
'Maak een Mailmerge met het bouwpartner bestand(Werkbalk afdruk samenvoegen)
Dim oMM As Word.Mailmerge
Set oMM = ActiveDocument.Mailmerge
oMM.MainDocumentType = wdFormLetters
oMM.OpenDataSource Name:=sNewPath & "\bouwpartners.xls", Connection:="TABLE", Format:=wdOpenFormatAuto, SQLStatement:="SELECT * FROM `bouwpartners$`"
oMM.OpenDataSource Name:= _
sNewPath & "\bouwpartners.xls", ConfirmConversions:=False, _
ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
WritePasswordTemplate:="", Revert:=False, Format:=wdOpenFormatAuto, _
Connection:= _
"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=sNewpath\Bouwpartners.xls;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet OLEDB:" _
, SQLStatement:="SELECT * FROM `Bouwpartners$`", SQLStatement1:="", _
SubType:=wdMergeSubTypeAccess
'Geef een melding aan de gebruiker dat hij meerdere bouwpartners kan selecteren
MsgBox ("Uw kunt 1 of meerdere bouwpartners selecteren. Wanneer u meerdere bouwpartners selecteert, dan zullen er meerdere documenten worden aangemaakt.")
'Open het venster met geadresseerden
Application.Dialogs(wdDialogMailMergeRecipients).Show (1)
ActiveDocument.Mailmerge.DataSource.SetAllIncludedFlags (False)
Application.Dialogs(wdDialogMailMergeRecipients).Show
Application.ScreenUpdating = False
'------ MAAK HET PRINT DOCUMENT / DOCUMENT MET ALLE BRIEVEN ONDER ELKAAR -----------------------------------------------------------------------------
'Zet de gekozen bouwpartners als 1 pagina per record in 1 document
With ActiveDocument.Mailmerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
End With
Selection.WholeStory 'selecteer alles
Selection.Font.Name = "Univers" 'maakt opmaak univers
'Maak opmaak volgens 2003
ActiveDocument.ApplyQuickStyleSet ("Word 2003")
'Bepaal de documentinstellingen (LET OP - DIT IS BIJ ELK SJABLOON ANDERS)
With ActiveDocument.Styles(wdStyleNormal).Font
If .NameFarEast = .NameAscii Then
.NameAscii = ""
End If
.NameFarEast = ""
End With
'Bepaal de printersintellingen
With ActiveDocument.PageSetup
.FirstPageTray = wdPrinterMiddleBin 'tray 2
.OtherPagesTray = wdPrinterLowerBin 'tray 3
End With
'Verander het te openen pad naar "standaard_doc" zodat deze daar opgeslagen kan worden
ChangeFileOpenDirectory strActivePad
'Sla het bestand met per pagina een record op als Printen.doc op betreffende project / standaarddoc
ActiveDocument.SaveAs FileName:="Printen.doc", FileFormat:=wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:=False
'Sluit het Printen document tbv de paginatelling
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
'Open het Printen document
Documents.Open FileName:=strActivePad & "\Printen.doc", ReadOnly:=False 'met alleen lezen beperking
Application.ScreenUpdating = True
|