VBAで関数を呼び出すときにプロパティは不正ですってなります
2つの関数を1つに結合すると発生しないのですが、なぜでしょうか?
上:エラーになる
下:通る
VBA
1Sub modify_one(wb As Worksheet) 2 On Error Resume Next 3 Dim words() As String, dir As String 4 Dim objFSO As New FileSystemObject 5 With wb 6 dir = objFSO.GetFileName(.Range("B18").Value) 7 8 words = Split(dir, "_") 9 rename words, .name 10 11 End With 12End Sub 13 14'シートの修飾関数、引数の文字列はファイルを_で分解 15Sub rename(words() As String, wbName As String) 16 ' エラーが発生しても無視して処理を継続させる 17 On Error Resume Next 18 With Worksheets(wbName) 19 'シート名。./()や同一名のシートがあるとエラーを吐くが無視してゴリゴリ進める 20 .name = words(1) & "_" & words(2) & "_" & words(3) & "_" & words(UBound(words) - 4) 21 'モード名 22 .Range("D10").Value = words(1) 23 .Range("D12").Value = Join(words, "") 24 .Range("D14").Value = Right(words(UBound(words) - 4), 3) 25 End With 26End Sub 27
VBA
1Sub modify_one(wb As Worksheet) 2 On Error Resume Next 3 Dim words() As String, dir As String 4 Dim objFSO As New FileSystemObject 5 With wb 6 dir = objFSO.GetFileName(.Range("B18").Value) 7 8 words = Split(dir, "_") 9 Debug.Print (dir) 10 Debug.Print (.name) 11 'rename words, .name 12 13 .name = words(1) & "_" & words(2) & "_" & words(3) & "_" & words(UBound(words) - 4) 14 'モード名 15 .Range("D10").Value = words(1) 16 17 .Range("D12").Value = Join(words, "") 18 .Range("D14").Value = Right(words(UBound(words) - 4), 3) 19 End With 20End Sub
回答2件
あなたの回答
tips
プレビュー