nochmal Word nach Excel
ing.grohnl
bei der Übergabe von Excel nach Word hab ich immer wieder Probleme:
Entweder er meldet (in Excel): "der Remote-Server ist nicht verfügbar..."
oder es kommt: "Fehler 4248, dieser Befehl ist nicht verfügbar, weil kein Dokument geöffnet ist."
(das Dokument seh ich aber auf dem Bildschirm)
Beide Fehler kommen in den Zeilen:
ObjWord.ActiveDocument.Close (wdDoNotSaveChanges)
ObjWord.Application.Quit
vor.
Auch wird unter XP nicht immer Word beendet!?
Hier kommt der Code:
Sub Ueberweisung()
Dim Anrede As String
Dim Name As String
Dim Vorname As String
Dim Strasse As String
Dim DocNeu As Object
Dim ObjWord As Object
Dim Bank As String
Dim Konto As String
Dim BLZ As String
Dim Betrag As String
Dim eName As String
Dim eKonto As String
Dim Verwendung1 As String
Dim Verwendung2 As String
Dim Datum As String
Set frm3 = UserForm3
With frm3
Vorname = .TextBox1.Value
Konto = .TextBox2.Value
BLZ = .TextBox3.Value
Bank = .TextBox9.Value
Betrag = .TextBox4.Value
Verwendung1 = .TextBox5.Value
Verwendung2 = .TextBox6.Value
eName = .TextBox7.Value
eKonto = .TextBox8.Value
Datum = Date
End With
On Error Resume Next
Set ObjWord = GetObject("Word.Application")
If ObjWord Is Nothing Then
Set ObjWord = CreateObject("Word.Application")
ObjWord.Visible = True
End If
On Error GoTo 0
If Not ObjWord Is Nothing Then
Set DocNeu = Word.Application.Documents.Add(Template:= _
"C:\Eigene Dateien\Vorlagen\Ueberweisung.dot")
End If
With DocNeu
If Len(LTrim(Vorname)) > 0 Then
.FormFields("Vorname").Result = Vorname
End If
If Len(LTrim(Name)) > 0 Then
.FormFields("Name").Result = Name
End If
If Len(LTrim(Konto)) > 0 Then
.FormFields("Konto").Result = Konto
End If
If Len(LTrim(BLZ)) > 0 Then
.FormFields("Blz").Result = BLZ
End If
If Len(LTrim(Bank)) > 0 Then
.FormFields("Bank").Result = Bank
End If
.FormFields("Betrag").Result = Betrag
.FormFields("Zweck1").Result = Verwendung1
.FormFields("Zweck2").Result = Verwendung2
.FormFields("eName").Result = eName
.FormFields("eKonto").Result = eKonto
.FormFields("Datum").Result = Datum
End With
DocNeu.Application.DisplayAlerts = wdAlertsNone
DocNeu.Application.Activate
DocNeu.Application.PrintOut
ObjWord.ActiveDocument.Close (wdDoNotSaveChanges)
ObjWord.Application.Quit
Set DocNeu = Nothing
Set ObjWord = Nothing
End Sub
Dieses Modul wird aus einer Userform aus aufgerufenFür eine Hilfe bedanke ich mich.
Mit freundlichen Grüßen
Albrecht