Das Notes Forum
Lotus Notes / Domino Sonstiges => OLE/COM-Programmierung => Thema gestartet von: Andysun am 20.02.08 - 17:50:04
-
Hallo zusammen,
ich möchte den bestehenden Inhalt einer Worddatei auslesen und in eine neue Worddatei , die bereits Text enthält, am Ende einfügen.
Nur leider ignoriert er die Anweisung.
Kann mir bitte jemand helfen ?
Denke ich zu kompliziert ?
Hier der Programmcode
Set wordApp = CreateObject("Word.Application" )
Dir$(File1$, 0) = ""
Call wordApp.Documents.Open (File1e$)
wordApp.visible = False
If wordApp.ActiveDocument Is Nothing Then
Exit Sub
Elseif wordApp.ActiveDocument.Type <> "Text" Then
Exit Sub
Elseif Len(wordApp.ActiveDocument.Selection) > 3060 Then
Msgbox("Too long selectection")
Exit Sub
Elseif Len(wordApp.ActiveDocument.Selection) = 0 Then
Exit Sub
End If
wordApp.ActiveDocument.Selection.Copy
buffer(nCopy) = wordApp.ActiveDocument.Selection
nPaste = nCopy
nCopy = nCopy + 1
If nCopy > 4 Then
nCopy = 0
End If
If nBufferSize < 5 Then
nBufferSize = nBufferSize + 1
End If
wordApp.ActiveDocument.Close
Set wordApp = CreateObject("Word.Application" )
Dir$(File2$, 0) = ""
Call wordApp.Documents.Open (File2$)
wordApp.visible = False
If wordApp.ActiveDocument Is Nothing Then
Exit Sub
Elseif wordApp.ActiveDocument.Type <> "Text" Then
Exit Sub
End If
If nBufferSize = 0 Then
Msgbox("Empty buffer")
Exit Sub
End If
wordApp.ActiveDocument.Selection = ""
curCol = wordApp.ActiveDocument.Selection.CurrentColumn
curLine =wordApp.ActiveDocument.Selection.CurrentLine
'get rid of new lines to obtain actulal string lenght
tempPasteStr = buffer(nPaste)
tempPasteStr = Replace(tempPasteStr, String(1, vbCr), "")
Dim pasteStrLen
pasteStrLen = Len(tempPasteStr)
wordApp.ActiveDocument.Selection = buffer(nPaste)
If pasteStrLen < 400 Then
ActiveDocument.Selection.MoveTo curLine, curCol
ActiveDocument.Selection.CharRight dsExtend, pasteStrLen
End If
nPaste = nPaste + 1
If nPaste >= nBufferSize Then
nPaste = 0
End If
wordApp.ActiveDocument.SaveAs File2$
wordApp.ActiveDocument.Close
Die Zweite Datei wird auch angelegt, nur leider ist der zu kopierende Inhalt nicht enthalten.
Beste Grüsse
Andreas
-
Wenn es rein um das Anhängen des Inhalts aus einem Worddokument an das Ende eines bestehenden Dokumentes geht, dann denkst du hier viel zu kompliziert.
Was mir auch beim Querlesen des Codes auf die Schnelle aufgefallen ist: warum legst du zwei Instanzen von Word an?
Set wordApp = CreateObject("Word.Application" )
Dir$(File1$, 0) = ""
Call wordApp.Documents.Open (File1e$)
wordApp.visible = False
....
If nBufferSize < 5 Then
nBufferSize = nBufferSize + 1
End If
wordApp.ActiveDocument.Close
Set wordApp = CreateObject("Word.Application" )
Dir$(File2$, 0) = ""
Call wordApp.Documents.Open (File2$)
....
Das Anhängen lässt sich aber leichter mit dem Befehl Einfügen - Datei erledigen.
Die notwendigen Schritte ganz grob skizziert:
1. Dokument öffnen
Einfügemarke ans Ende des Dokumentes setzen (über vordefinierte Textmarke \EndOfDoc)
Mit Selection.InsertFile FileName:="Dokumentname.doc",... den Inhalt des zweiten Dokumentes einfügen.
1. Dokument speichern
Das sollte eingentlich reichen.
Axel
-
Vielen Dank Alex,
du hast recht, viel zu kompliziert.
Ich habe folgende Lösung gefunden:
Call wordApp.Documents.Open (File1$)
wordApp.Selection.Homekey 6
wordApp.Selection.WholeStory
wordApp.Selection.Font.Size = 8
wordApp.Selection.Font.Name = "arial"
'wordApp.Selection.Font.Style = wordApp.ActiveDocument.Styles("Standard")
'wordApp.Selection.ParagraphFormat.Alignment = wdAlignParagraphJustify
wordApp.Selection.Copy
wordApp.visible = False
Call wordApp.Documents.Open (File2$)
wordApp.Selection.EndKey 6
wordApp.Selection.Paste
wordApp.visible = False
wordApp.ActiveDocument.Save
wordApp.Documents.Close False
wordApp.Quit
beste Grüsse
Andy
-
So geht's natürlich auch.
Axel