2017-01-10 6 views
-2

指定された図形名とその内部のテキストを含むテキストファイルを出力する必要があります。図形からテキストを読み取るときに値が範囲外です。

私は取得していますエラーは、指定された値が範囲外である

実行時エラー「-2147024809(80070057)」です。私のPCで

Sub test() 
Dim objFSO As Object, objFile 
Set objFSO = CreateObject("Scripting.FileSystemObject") 
Set objFile = objFSO.OpenTextFile("C:\Users\[user]\Documents\text.txt", 2) 
objFile.Write "" 'This clears the text file 

Dim obj As Shape 

For Each obj In ActiveSheet.Shapes 
    sWrite = obj.Name & "; Content: " & obj.TextFrame2.TextRange.Characters.text 
    Debug.Print sWrite 
    objFile.WriteLine sWrite 
Next obj 
objFile.Close 
End Sub 
+0

あなたは*添字*範囲外であることを意味するのですか? – Comintern

+0

正確なエラーとはどのような行ですか? –

+0

'sWrite = obj.Name & ";内容:"&obj.TextFrame2.TextRange.Characters(0、300) 'この行はあなたの問題ですか?300文字を持たない場合は、範囲外の添字を取得しますエラー。 – Kyle

答えて

0

コードは正常に動作

Sub test() 
Dim objFSO As Object 
Dim objFile As Object' here is your problem 

Set objFSO = CreateObject("Scripting.FileSystemObject") 
Set objFile = objFSO.OpenTextFile("C:\Users\[user]\Documents\Proyect folder\otros\test & intentions\test.txt", 2) 
objFile.Write "" 'This clears the text file 

Dim obj As Shape 

For Each obj In ActiveSheet.Shapes 
    sWrite = obj.Name & "; Content: " & obj.TextFrame2.TextRange.Characters.Text 
    Debug.Print sWrite 
    objFile.WriteLine sWrite 
Next obj 
objFile.Close 
End Sub 
+0

は以前と同じエラーが返ってきましたが、全体をコピーして貼り付けて参照を調整しました。しかし、ありがとう。実際に私はちょうどそれを把握した、それがつかむ第5の形は、テキストがない矢印だったので、スクリプトがそれになったときにスクリプトがエラーを出した –

関連する問題