Thema Datum  Von Nutzer Rating
Antwort
18.11.2014 14:56:22 Mara
NotSolved
19.11.2014 10:37:06 Gast60144
Solved
20.11.2014 15:12:15 Gast58649
NotSolved
20.11.2014 19:59:39 Gast13621
NotSolved
24.11.2014 08:27:23 Mara
NotSolved
24.11.2014 08:40:15 Mara
NotSolved
24.11.2014 09:25:08 Gast92691
NotSolved
25.11.2014 07:17:57 Mara
NotSolved
03.12.2014 11:09:21 Mara
NotSolved
03.12.2014 11:25:21 Ambg
NotSolved
03.12.2014 11:30:43 Gast96518
NotSolved
03.12.2014 14:50:36 Mara
NotSolved
Rot Run-time error
03.12.2014 15:18:58 Ambg
NotSolved
09.12.2014 15:27:19 Mara
NotSolved
09.12.2014 20:11:17 Ambg
NotSolved
10.12.2014 15:31:23 Mara
NotSolved

Ansicht des Beitrags:
Von:
Ambg
Datum:
03.12.2014 15:18:58
Views:
1116
Rating: Antwort:
  Ja
Thema:
Run-time error

Am Code liegt es sicher nicht – eher an (d)einer Schleife!

Hab das mal kurz aufgebohrt, aber nichts Wesentliches verändert.

OK – process-explorer zeigt, dass Excel & Co. ganz schön rappeln,

aber immer noch im zugeteilten working-set

1
2
(gesamt 6 Dateien mit 50 - 200 Seiten und 250 - 550 Ersetzungen
und Laufzeit 4 - 24 sec)

 

Run-time error '-2147417851 (80010105)'

 klingt für mich wie ein Dateisystemfehler Made by Windows

 

In die Test() mal eine Fehlerbehandlung eingebaut, ob der Fehler abzufangen

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
Option Explicit
 
Sub Schleife()
'
' Vorgaben:
' aktive Excel-Tabelle
' [A1] - Pfad zum Word Dokument (hier: E:\Temp\Test.docx)
' [A2] - [Ax] Suchbegriffe
 
' [B1] - Pfad zum Word Dokument (hier: C:\Temp\Tast.docx)
' [B2] - [Bx] Suchbegriffe
 
' usw.
 
' gesamt 6 Dateien mit 50 - 200 Seiten und 250 - 550 Ersetzungen
 
Dim oWsh As Excel.Worksheet
Dim rngc As Excel.Range       'alles
Dim rngF As Excel.Range       'Dateinamen
Dim rngT As Excel.Range       'Ersetzungsliste
Dim x As Long
 
Set oWsh = ThisWorkbook.ActiveSheet
 
For x = 1 To oWsh.UsedRange.Columns.Count
   Set rngc = Range(Cells(1, x), Cells(1, x).End(xlDown))
   Set rngF = rngc.Cells(1)    'Datei
   Set rngT = rngc.Offset(1, 0).Resize(rngc.Rows.Count - 1, _
      rngc.Columns.Count)
   'Debug.Print rngc.Address, rngF.Address, rngT.Address
   MeinTest rngF, rngT
Next x
 
End Sub
 
 
Private Sub MeinTest(rngFile As Range, rngSubst As Range)
'******************************************************************************
'
Dim oExcelList As Object
Dim oExcelSheet As Excel.Worksheet
Dim c As Excel.Range
Dim oWordApp As Word.Application
Dim oWordDoc As Word.Document
Dim wdr As Word.Range
Dim sText As String
Dim lCnt As Long, lFnd As Long
   
Set oExcelSheet = ThisWorkbook.ActiveSheet
 
Set oExcelList = CreateObject("System.Collections.ArrayList")
   
   oExcelList.Add rngFile.Text
    
   For Each c In rngSubst
      oExcelList.Add c.Text
    
   Next c
   
Set oWordApp = CreateObject("Word.Application")
Set oWordDoc = oWordApp.Documents.Open(oExcelList.Item(0))
   
With oWordDoc
   Set wdr = .Content
   For lCnt = 1 To oExcelList.Count - 1
      sText = oExcelList.Item(lCnt)
      lFnd = 0
      Do
         wdr.Find.Execute FindText:=sText, Forward:=True
         If Not wdr.Find.Found Then Exit Do
         With wdr
            .Bold = True
            .Font.ColorIndex = wdRed
         End With
         lFnd = lFnd + 1
         oExcelList.Item(lCnt) = sText & Format(lFnd, " #0 Ersetzungen")
      Loop
      Set wdr = .Content
   Next lCnt
End With
   
oWordDoc.Close
oWordApp.Quit
   
Call MsgBox(Join(oExcelList.toarray(), Chr(10)), vbInformation, "Geschafft!")
   
Set oWordApp = Nothing
Set oWordDoc = Nothing
Set wdr = Nothing
Set oExcelSheet = Nothing
Set oExcelList = Nothing
   
End Sub
 
 
'*******************************************************************************
'hier einmal eine Fehlersteuerung eingebaut
'ob überhaupt abzufangen
Sub Test()
'
'******************************************************************************
' Name : Test / erstellt : 03.12.2014 / 15:10 / Sub
'------------------------------------------------------------------------------
'
'
'
Const m_ModName As String = "mdl_FindInWordDoc"
Const m_PrcName As String = "Test"
Dim m_SendKey As String: m_SendKey = Chr(123) & "F8" & Chr(125)
'
'******************************************************************************
'
'
' Vorgaben:
' aktive Excel-Tabelle
' [A1] - Pfad zum Word Dokument (hier: E:\Temp\Test.docx)
' [A2] - [Ax] Suchbegriffe
'******************************************************************************
'
 
Dim oExcelList As Object
Dim oExcelSheet As Excel.Worksheet
Dim c As Excel.Range
Dim oWordApp As Word.Application
Dim oWordDoc As Word.Document
Dim wdr As Word.Range
Dim sText As String
Dim lCnt As Long, lFnd As Long
   
'
   On Error GoTo Test_Error
   'lCnt = lCnt / 0 Test
'
Set oExcelSheet = ThisWorkbook.ActiveSheet
Set c = oExcelSheet.Range("A1")
Set oExcelList = CreateObject("System.Collections.ArrayList")
   
   oExcelList.Add c.Text
   Set c = c.Offset(1)
   Do While c.Text <> vbNullString
      oExcelList.Add c.Text
      Set c = c.Offset(1)
   Loop
   
Set oWordApp = CreateObject("Word.Application")
Set oWordDoc = oWordApp.Documents.Open(oExcelList.Item(0))
   
With oWordDoc
   Set wdr = .Content
   For lCnt = 1 To oExcelList.Count - 1
      sText = oExcelList.Item(lCnt)
      lFnd = 0
      Do
         wdr.Find.Execute FindText:=sText, Forward:=True
         If Not wdr.Find.Found Then Exit Do
         With wdr
            .Bold = True
            .Font.ColorIndex = wdRed
         End With
         lFnd = lFnd + 1
         oExcelList.Item(lCnt) = sText & Format(lFnd, " #0 Ersetzungen")
      Loop
      Set wdr = .Content
   Next lCnt
End With
   
oWordDoc.Close
oWordApp.Quit
   
Call MsgBox(Join(oExcelList.toarray(), Chr(10)), vbInformation, "Geschafft!")
'
   On Error GoTo 0
'
Test_Error:
'------------------------------------------------------------------------------
Select Case Err.Number
  Case Is = 0: 'errorless
  ' Case is = #: 'custom
  Case Else: 'display
      Select Case MsgBox(Format(Err.Number, "   #0") & "/" & Err.Description & _
         Chr(13) & Chr(13) & "   Debugmodus starten ?", _
         vbYesNo Or vbCritical Or vbDefaultButton1, _
         m_ModName & " / " & m_PrcName)
      Case vbYes
         Application.SendKeys Keys:=m_SendKey & m_SendKey, Wait:=False
         Stop: Resume
      Case vbNo
         ' Abbruch
   End Select
End Select
'------------------------------------------------------------------------------
   
End Sub

 

 

 


Ihre Antwort
  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen
Thema: Name: Email:



  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen

Thema Datum  Von Nutzer Rating
Antwort
18.11.2014 14:56:22 Mara
NotSolved
19.11.2014 10:37:06 Gast60144
Solved
20.11.2014 15:12:15 Gast58649
NotSolved
20.11.2014 19:59:39 Gast13621
NotSolved
24.11.2014 08:27:23 Mara
NotSolved
24.11.2014 08:40:15 Mara
NotSolved
24.11.2014 09:25:08 Gast92691
NotSolved
25.11.2014 07:17:57 Mara
NotSolved
03.12.2014 11:09:21 Mara
NotSolved
03.12.2014 11:25:21 Ambg
NotSolved
03.12.2014 11:30:43 Gast96518
NotSolved
03.12.2014 14:50:36 Mara
NotSolved
Rot Run-time error
03.12.2014 15:18:58 Ambg
NotSolved
09.12.2014 15:27:19 Mara
NotSolved
09.12.2014 20:11:17 Ambg
NotSolved
10.12.2014 15:31:23 Mara
NotSolved