Sub
Schaltfläche1_Klicken()
Dim
Wordapp
As
Object
, Worddoc
As
Object
Dim
letzteZelle
As
String
, Pfad
As
String
, Ersteller
As
String
, Thema
As
String
, Fach
As
String
, Lehrer
As
String
, Vorlage
As
String
, Protokollname
As
String
Dim
Schreibbereich
As
Range
Dim
zellenindex
As
Integer
With
ThisWorkbook.ActiveSheet
Set
Wordapp = CreateObject(
"Word.application"
)
Vorlage = .Cells(8, 1)
Wordapp.Documents.Add Vorlage &
"Protokollvorlage.dotx"
Pfad = .Cells(6, 1)
letzteZelle = .Cells(Rows.Count, 2).
End
(xlUp).Row - 10
Thema = .Cells(Rows.Count, 2).
End
(xlUp).Value
Ersteller = .Cells(Rows.Count, 3).
End
(xlUp).Value
Fach = .Cells(Rows.Count, 4).
End
(xlUp).Value
Lehrer = .Cells(Rows.Count, 5).
End
(xlUp).Value
If
Lehrer =
"Ziegert"
Then
Pfad = Pfad & "Ziegert\Protokoll\"
ElseIf
Lehrer =
"Tschersich"
Then
Pfad = Pfad & "Tschersich\Protokoll\"
ElseIf
Lehrer =
"Bues"
Then
Pfad = Pfad & "Bues\Protokoll\"
ElseIf
Lehrer =
"Mundt"
Then
Pfad = Pfad & "Mundt\Protokoll\"
End
If
Set
Worddoc = Wordapp.ActiveDocument
With
Worddoc
.BuiltinDocumentProperties(
"Title"
).Value = Thema
.BuiltinDocumentProperties(
"Manager"
).Value = Lehrer
.BuiltinDocumentProperties(
"Category"
).Value = Fach
.BuiltinDocumentProperties(
"Author"
).Value = Ersteller
.BuiltinDocumentProperties(
"Subject"
).Value =
Date
End
With
Protokollname = letzteZelle &
"_"
&
Date
&
"_"
& Thema &
".docx"
.Cells(letzteZelle + 10, 1).
Select
.Hyperlinks.Add Anchor:=Selection, Address:=Pfad & Protokollname
.Cells(letzteZelle + 10, 1).Value = Protokollname
Worddoc.SaveAs (Pfad & Protokollname)
Wordapp.Documents.Open Pfad & Protokollname
Wordapp.Activate
zellenindex = Cells(Rows.Count, 1).
End
(xlUp).Row
Set
Schreibbereich = Range(
"A"
& zellenindex &
":E"
& zellenindex)
Schreibbereich.
Select
With
Selection.Interior
.ThemeColor = xlThemeColorDark1
End
With
End
With
ThisWorkbook.Worksheets(
"Tabelle2"
).Activate
ThisWorkbook.Worksheets(
"Tabelle1"
).Activate
End
Sub
____________________________________________________________
Private
Sub
Worksheet_Activate()
Dim
Schreibbereich
As
Range
Dim
zellenindex
As
Integer
zellenindex = Cells(Rows.Count, 1).
End
(xlUp).Row + 1
Set
Schreibbereich = Range(
"A"
& zellenindex &
":E"
& zellenindex)
Schreibbereich.
Select
With
Selection.Interior
.Color = 65535
End
With
End
Sub