AW: Word-Datei zeilenweise einlesen und speichern
12.08.2017 16:54:21
Luschi
Hallo Sepp,
beim Testen Deines Tipps mit Word 2016 kommt hier ein Fehler:
.Documents.Open strFile, , True
Deshalb habe ich eine kleine Änderung eingebaut:
Sub inputWordFile()
Dim objWord As Object, objDoc As Object
Dim strFile As String, lngI As Long, strText() As String, strTmp As String
With Application.FileDialog(msoFileDialogFilePicker)
.InitialFileName = "F:\Daten\Downloads\"
.Title = "Datei auswählen"
.ButtonName = "Auswahl..."
.InitialView = msoFileDialogViewList
.Filters.Clear
.Filters.Add "Word Dateien", "*.doc; *.doc*", 1
.FilterIndex = 1
If .Show = -1 Then strFile = .SelectedItems(1)
End With
If Len(strFile) Then
Set objWord = CreateObject("Word.Application")
With objWord
.Visible = False
''Worddatei schreiabgeschützt öffnen
''statt
''.Documents.Open strFile, , True
Set objDoc = .Documents.Open(strFile, , True)
.WordBasic.EditSelectAll
.WordBasic.SetDocumentVar "MyVar", .WordBasic.Selection
strTmp = .WordBasic.GetDocumentVar("MyVar")
'Fehler 4605 - Befehl im Lesemodus nicht verfügbar
'.Documents.Close (0)
objDoc.Close False
.Quit
End With
strText = Split(strTmp, vbCr)
'Der Text befindet sich nun im Array strText
'Ausgabe in Zellen
Sheets("Tabelle1").Range("A1").Resize(UBound(strText) + 1, 1) = Application.Transpose( _
strText)
End If
Set objWord = Nothing: Set objDoc = Nothing
End Sub
Gruß von Luschi
aus klein-Paris