Hallo,
ich habe ein problem mit meinem programm, ich öffne eine WordVorlage übertrage die Daten anschließend speiher und schließe ich Word. Beim zweiten Aufruf bekomm ich den "Laufzeitfehler 462 - The remote server machine does not exist or is unavailable"
code:
Private Sub openWord()
Dim sql As String
Dim X As Integer
Dim WordAppl As Word.Application
Dim WdDoc As Word.Document
Dim zeile As Integer
Dim spalte As Integer
zeile = flexgrid.Rows
spalten = 3
Set WordAppl = CreateObject("Word.Application")
Set WdDoc = WordAppl.Documents.Add(Template:=App.Path & _
"/SD-MB-1-Vorlage1", NewTemplate:=False)
WordAppl.Application.Visible = True
If WordAppl.ActiveDocument.Bookmarks.Exists("TmStand") Then
WordAppl.ActiveDocument.Bookmarks("TmStand").Range.Text = txtDatum.Text
End If
If WordAppl.ActiveDocument.Bookmarks.Exists("TmKdNr") Then
WordAppl.ActiveDocument.Bookmarks("TmKdNr").Range.Text = txtNr.Text
End If
If WordAppl.ActiveDocument.Bookmarks.Exists("TmKdName") Then
WordAppl.ActiveDocument.Bookmarks("TmKdName").Range.Text = _
txtKdName.Text
End If
If WordAppl.ActiveDocument.Bookmarks.Exists("TmArtikelNr") Then
WordAppl.ActiveDocument.Bookmarks("TmArtikelNr").Range.Text = cmbArtikel
End If
If WordAppl.ActiveDocument.Bookmarks.Exists("tmTab") Then
With WordAppl
.Selection.GoTo What:=wdGoToBookmark, Name:="tmTab"
[u].ActiveDocument.Tables.Add Range:=Selection.Range, _
NumRows:=zeile, NumColumns:=spalten, _
DefaultTableBehavior:=wdWord9TableBehavior, _
AutoFitBehavior:=wdAutoFitFixed
.Selection.TypeText "Artikel Nr"
.Selection.MoveRight
.Selection.TypeText "R-/S-Sätze"
.Selection.MoveRight
.Selection.TypeText "Gefahrensymbol"
.Selection.MoveStart
For X = 1 To zeile - 2
sql = " Select * from Rohstoffe where Rohstoff_Nr like '" & _
flexgrid.TextMatrix(X, 0) & "'"
rsrohstoffe2.Open sql, Con, adOpenStatic, adLockOptimistic, _
adCmdText
.Selection.TypeText flexgrid.TextMatrix(X, 0) '
' rsrohstoffe2.Fields(1)
.Selection.MoveRight
If IsNull(rsrohstoffe2.Fields(5)) = False Then
.Selection.TypeText rsrohstoffe2.Fields(5)
End If
If IsNull(rsrohstoffe2.Fields(6)) = False Then
.Selection.TypeText ", " & rsrohstoffe2.Fields(6)
End If
If IsNull(rsrohstoffe2.Fields(7)) = False Then
.Selection.TypeText ", " & rsrohstoffe2.Fields(7)
End If
...
.Selection.MoveDown
.Selection.MoveLeft , 2
rsrohstoffe2.Close
Next X
End With
End If
WdDoc.Close
Set WdDoc = Nothing
WordAppl.Quit
Set WordAppl = Nothing
End Sub underline = Fehler
Wie kann ich den Code umwandeln damit ich mehrere WordVorlage hintereinander öfnen kann. |