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:
956
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

(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

 

 

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