これは私の試みです。
Sub getDataforFile()
Dim objFSO As Object
Dim objFile As Object
Dim filePath As String
Dim myRange As Range
Dim myCell As Range
Set objFSO = CreateObject("Scripting.FileSystemObject")
'this assigns your selection, everything on Colum B to a Range variable
Set myRange = Selection
filePath = "C:\Output.txt" 'put your own path
Set objFile = objFSO.CreateTextFile(filePath)
For Each myCell In myRange
'if the value in Column B is a number and not an empty string
If IsNumeric(myCell.Value) And Not myCell.Value = "" Then
'write to the text file, first moving two columns over to the right,
'no rows down, concatenating a comma, and then again moving two columns
'right, one row down, all from the original range, on Column B
objFile.writeline myCell.Offset(0, 2).Value & ", " & myCell.Offset(1, 2).Value
End If
'continue checking each cell in the selection
Next myCell
objFile.Close
Set objFile = Nothing
Set objFSO = Nothing
End Sub
うーん:あなたは、持ち込まれた列Bに対応する数値を持ってする必要がある値のように、あなたのポストを形成し、私は仮定の多くの操作B列のすべての値を選択します。このコードは私には大変意味がありますが、何らかの理由で、「実行時エラー '5':無効なプロシージャ呼び出しまたは引数」が表示されます。デバッガは私にこの行を指摘します: 'objFile.writeline myCell.Offset(0、2).Value&"、 "&myCell.Offset(1,2).Value' – Raider61
これは問題ではないと思います。参照のWindowsスクリプトホストオブジェクトモデルを追加するほうが役に立ちます。 –
問題を解明しました。私のテキストはアジア系の文字なので、VBAはそれを拾っていませんでした。あなたのコードは素晴らしいですが、ありがとう! – Raider61