0
に戻すとVBAプログラミングに非常に新しいので、助けてください。私は、私が立ち往生している部分は、少なくとも私の関数呼び出しで常にエラーが発生していると思うときに、CSV文字列に値を変換する関数に送信するセルの範囲を作成しようとしています。ここでの究極の目標は、実行のためにシェルコマンドに送る文字列をアセンブルすることです。私は、受信エラーがこの行の型が一致している:VBA Excel 2007で機能するセルの範囲を送信しようとしていて、文字列を
File_Index = Range2Csv( "E20:" & N_small_files)ここで
は私のコードは次のとおりです。
を探しているため
Option Explicit
Sub TDMS_Click()
Dim Big_File As String
Dim Small_File As String
Dim File_Index As String
Dim N_small_files As String
Dim File_Duration As Integer
Dim TDMS_exe As String
Dim EXE_command As String
TDMS_exe = "blah/blah blah/blah.exe"
N_small_files = ActiveCell.Address(RowAbsolute:=False, ColumnAbsolute:=True)
File_Index = Range2Csv("E20:" & N_small_files)
Big_File = Worksheets("Sheet1").Cells(6, 3)
Small_File = Worksheets("Sheet1").Cells(9, 3)
File_Duration = Worksheets("Sheet1").Cells(12, 3)
EXE_command = TDMS_exe & " -- " & File_Duration & Big_File & Small_File & """" & File_Index & """"
Range("H40").Value = EXE_command
End Sub
'**********************************************
'* PURPOSE: Concatenates range contents into a
'* delimited text string
'*
'* FUNCTION SIGNATURE: Range2Csv(Range, String)
'*
'* PARAMETERS:
'* Range - the range of cells whose contents
'* will be included in the CSV result
'* String - delimiter used to separate values
'* (Optional, defaults to a comma)
'*
'* AUTHOR: www.dullsharpness.com
'*
'**********************************************
Public Function Range2Csv(inputRange As Range, Optional delimiter As String) As String
Dim concattedList As String 'holder for the concatted CSVs
Dim rangeCell As Range 'holder cell used in For-Each loop
Dim rangeText As String 'holder for rangeCell's text
'default to a comma delimiter if none is provided
If delimiter = "" Then delimiter = ","
concattedList = "" 'start with an empty string
'Loop through each cell in the range to append valid contents
For Each rangeCell In inputRange.Cells
rangeText = rangeCell.Value 'capture the working value
'Only operate on non-blank cells (i.e. Length > 0)
If Len(rangeText) > 0 Then
'Strip any delimiters contained w/in the value itself
rangeText = WorksheetFunction.Substitute(rangeText, delimiter, "")
If (Len(concattedList) > 0) Then
'prepend a delimiter to the new value if we
'already have some list items
concattedList = concattedList + delimiter + rangeText
Else
'else if the list is blank so far,
'just set the first value
concattedList = rangeText
End If
End If
Next rangeCell
'Set the return value
Range2Csv = concattedList
End Function
感謝Tim
完璧!ありがとうございました。 –