ich weiss nicht, ob es am "DIM"-Befehl liegt, dafür bin ich ein viel zu großer Laie. Aber ich hoffe Ihr könnt mir helfen...
Ich habe folgendes Problem bei der Verwendung des u.a. Makros: Die Word-Instanz wird gestartet. Jedoch bleibt es auch dabei. Sobald ich ein Dokument im Sub "Vordrucke" jedoch starten möchte, lässt sich Word nicht mehr steuern, d.h. er öffnet die Datei schon gar nicht.
Was mache ich falsch?
Danke und Grüße
Marco
Der Code:
Private Sub Druck_Start()
Dim appWD As Word.Application
Set appWD = CreateObject("Word.Application")
appWD.Visible = True
Druck.Abbrechen.Enabled = False
Druck.Drucken.Enabled = False
If Druck.D_BA_I_FW_115.Value = True Then
Dokumentname = "BA I FW 115.dot"
Dokumentbezeichnung = "Erhebungsbogen"
Vordrucke
End If
'...(weitere Dokumente)...
appWD.Quit
Druck.Status.Caption = ""
Druck.Abbrechen.Enabled = True
Druck.Drucken.Enabled = True
End Sub
Private Sub Vordrucke()
Druck.Status.Caption = Dokumentbezeichnung & " wird gedruckt..."
Application.Wait Now + 1 / 86400
MsgBox appWD
appWD.Documents.Add Template:=ActiveWorkbook.Path & "\Vorlagen\" & Dokumentname
'AppActivate appWD
appWD.DisplayAlerts = False
With appWD.ActiveDocument
.FormFields("Name").Result = BGEingabe.K_Name.Text
.FormFields("Vorname").Result = BGEingabe.K_Vorname.Text
.FormFields("Geb").Result = BGEingabe.K_Geb.Text
.FormFields("Amt").Result = BGEingabe.B_Amt.Text
.FormFields("Ziel").Result = BGEingabe.BGZiel.Text
.FormFields("KUNR").Result = BGEingabe.K_KUNR.Text
.Fields.Update
.Unprotect
.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
'ActiveDocument.PrintOut
ActiveDocument.Close wdDoNotSaveChanges
End With
End Sub