J***@web.de
2007-07-04 09:50:45 UTC
Hallo NG,
ich will gerade ein VB Script programmieren, das durch alle in einer
Word Datei eingebetteten Excel Objekte läuft. Dabei soll es in allen
Zellen in den Formeln einen Ausdruck durch einen anderen ersetzen.
Leider bekomme ich bei der Ausführung in der Zeile mit dem ersten
Range immer folgende Fehlermeldung:
"Laufzeitfehler '1004': Die Methode 'Range' für das Objekt '_Global'
ist fehlgeschlagen"
Hier ist einmal mein Code:
Dim strFnd As String 'Text that has to be searched and replaced
Dim strPst As String 'Text that has to be put in
'The routine SubSetGlblPrms() sets the parameters for this modul.
Sub SubSetGlblPrms()
Dim strPrmpt As String
Dim strTtl As String
strPrmpt = "Geben Sie den Pfad/Text ein, der in allen Excel
Objekten gesucht und ersetzt werden soll: "
strTtl = "Definition des Parameters ""strFnd"""
strFnd = InputBox(strPrmpt, strTtl)
strPrmpt = "Geben Sie den Pfad/Text ein, der in allen Excel
Objekten eingetragen/eingefügt werden soll: "
strTtl = "Definition des Parameters ""strPst"""
strPst = InputBox(strPrmpt, strTtl)
End Sub
'SubEdtPth() goes through all Excel objects in the word file and
replaces
'a part of the paths, which show up in the Excel formulas.
Sub SubEdtPth()
Dim strOrgn As String 'Original value from the addressed cell in
an excel object.
Dim intCl As Integer
Dim intRw As Integer 'Counter for indexing the rows in an Excel
object
Dim strClAddrss As String
Dim objInlnShp As InlineShape
'Set parameters.
SubSetGlblPrms
If strFnd = "" Or strPst = "" Then
MsgBox "Falsche Eingabe in den Eingabefeldern!"
Exit Sub
End If
intCnt = 1
'Runs through all the Excel objects and puts the focus on them.
For Each objInlnShp In ActiveDocument.InlineShapes
objInlnShp.OLEFormat.Edit
'For each column
For intCl = 65 To 84 Step 1
'For each row
For intRw = 1 To 35 Step 1
'Changing the relevant text data.
strClAddrss = Chr(intCl) + CStr(intRw)
strOrgn = CStr(Range(strClAddrss).FormulaLocal)
strOrgn = Replace(strOrgn, strFnd, strPst, 1, -1,
vbTextCompare)
Range(strClAddrss).FormulaLocal = strOrgn
Next
Next
Next
End Sub
Vermutlich kann der Befehl Range mein InlineShape Objekt nicht
adressieren. Allerdings wird für die Variable objInlnShp nach Eingabe
eines Punktes "Range" in der Befehlsliste aufgeführt.
Ich hoffe es kann mir jemand weiterhelfen.
Für alle Tipps im Voraus besten Dank.
Viele Grüße
Marc
ich will gerade ein VB Script programmieren, das durch alle in einer
Word Datei eingebetteten Excel Objekte läuft. Dabei soll es in allen
Zellen in den Formeln einen Ausdruck durch einen anderen ersetzen.
Leider bekomme ich bei der Ausführung in der Zeile mit dem ersten
Range immer folgende Fehlermeldung:
"Laufzeitfehler '1004': Die Methode 'Range' für das Objekt '_Global'
ist fehlgeschlagen"
Hier ist einmal mein Code:
Dim strFnd As String 'Text that has to be searched and replaced
Dim strPst As String 'Text that has to be put in
'The routine SubSetGlblPrms() sets the parameters for this modul.
Sub SubSetGlblPrms()
Dim strPrmpt As String
Dim strTtl As String
strPrmpt = "Geben Sie den Pfad/Text ein, der in allen Excel
Objekten gesucht und ersetzt werden soll: "
strTtl = "Definition des Parameters ""strFnd"""
strFnd = InputBox(strPrmpt, strTtl)
strPrmpt = "Geben Sie den Pfad/Text ein, der in allen Excel
Objekten eingetragen/eingefügt werden soll: "
strTtl = "Definition des Parameters ""strPst"""
strPst = InputBox(strPrmpt, strTtl)
End Sub
'SubEdtPth() goes through all Excel objects in the word file and
replaces
'a part of the paths, which show up in the Excel formulas.
Sub SubEdtPth()
Dim strOrgn As String 'Original value from the addressed cell in
an excel object.
Dim intCl As Integer
Dim intRw As Integer 'Counter for indexing the rows in an Excel
object
Dim strClAddrss As String
Dim objInlnShp As InlineShape
'Set parameters.
SubSetGlblPrms
If strFnd = "" Or strPst = "" Then
MsgBox "Falsche Eingabe in den Eingabefeldern!"
Exit Sub
End If
intCnt = 1
'Runs through all the Excel objects and puts the focus on them.
For Each objInlnShp In ActiveDocument.InlineShapes
objInlnShp.OLEFormat.Edit
'For each column
For intCl = 65 To 84 Step 1
'For each row
For intRw = 1 To 35 Step 1
'Changing the relevant text data.
strClAddrss = Chr(intCl) + CStr(intRw)
strOrgn = CStr(Range(strClAddrss).FormulaLocal)
strOrgn = Replace(strOrgn, strFnd, strPst, 1, -1,
vbTextCompare)
Range(strClAddrss).FormulaLocal = strOrgn
Next
Next
Next
End Sub
Vermutlich kann der Befehl Range mein InlineShape Objekt nicht
adressieren. Allerdings wird für die Variable objInlnShp nach Eingabe
eines Punktes "Range" in der Befehlsliste aufgeführt.
Ich hoffe es kann mir jemand weiterhelfen.
Für alle Tipps im Voraus besten Dank.
Viele Grüße
Marc