bei folgender Schleife, welche Dokumente kopieren soll und diese anschließend beschriften, ergeben sich Fehler bei den IFs am Schluss.....
Die kursiv markierten IFs und Nexts werden komischerweise als
"End IF ohne IF/Next ohne For"
deklariert.
Leider finde ich auch nach mehrmaligen Probieren nicht heraus was, wieso er mir plötzlich hier einen Fehler ausgibt. Ich habe dabei den fett-gedruckten Code eingefügt, davor lief die Schleife ohne Probleme durch.
Freue mich über Hilfe ....
VG
Debugger
Sub DokumenteAnlegen()
Dim pre, Projekt As String
pre = ActiveWorkbook.Sheets("Eingabefenster").Cells(7, 2)
Projekt = ActiveWorkbook.Sheets("Eingabefenster").Range("B5").Value
Dim x As Integer
Dim m As Integer
Dim I As Integer
Dim a As Integer
Dim b As Integer
Dim Dokumente As Variant
Dim DokumenteSource As Variant
m = Sheets("Dokumente").Cells(1, 1).End(xlToRight).Column
x = 1
For x = 1 To m
I = Sheets("Dokumente").Cells(1, x).End(xlUp).Row
Dokumente = (Sheets("Dokumente").Cells(2, x).Value)
For I = 1 To x
With Worksheets("Quelle")
a = .Cells(1, x).CurrentRegion.Rows.Count
For b = 1 To a
DokumenteSource = (Sheets("Quelle").Cells(b, x))
Dokumente = (Sheets("Dokumente").Cells(b + 1, x))
If Dokumente "" Then
If (Dir(Sheets("Dokumente").Cells(1, x).Value)) = "" Then
If DokumenteSource "" Then
FileCopy DokumenteSource, Dokumente
If Right(Dokumente, 5) = ".docx" Then
Const wdReplaceAll = 2
Dim AppWD As Object, AppDoc As Object
Dokumente = ActiveWorkbook.Sheets("Dokumente").Range("C2"). _
Value
If Dir(Dokumente) "" Then
Set AppWD = CreateObject("Word.Application") 'Word als Object _
_
_
starten
If Not AppWD Is Nothing Then
AppWD.Visible = True
Set AppDoc = AppWD.documents.Open(Dokumente)
If Not AppDoc Is Nothing Then
With AppDoc.Range.Find
.Text = "Test"
.MatchCase = True
.Replacement.Highlight = True
.Replacement.Text = ActiveWorkbook.Sheets("Eingabefenster"). _
Range("B5").Value
.Execute Replace:=wdReplaceAll
End With
Else
Dim strText As String, Wsh As Worksheet
Workbooks.Open (Dokumente)
strText = "Ersatz"
For Each Wsh In ActiveWorkbook.Worksheets
Wsh.UsedRange.Replace "Test", strText, xlPart
Else
MsgBox "Die zu öffnende Dokumentdatei wurde nicht gefunden!", vbCritical, " _
_
_
Word-Datei öffnen"
End If
End If
Next b
Next x
Next m
End Sub