단어 사이에 공백이있는 CSV 파일의 배열과 모든 공백을 하이픈으로 바꾼 후에 채우려는 두 번째 파일의 배열에 채우려고합니다.단어 vba 텍스트 사이에 배열 바꾸기
그래서 array1의 내용은 "Hi there"와 같고 array2의 내용은 "Hi-there"처럼 보입니다.
replace (text, old, new)를 사용해 보았지만 문제가 있습니다. 다른 하위가없는 독립형 매크로에서는 작동합니다. 다른 서브 우퍼가있는 경우 그것을하지 않습니다, 던지고 및 오류가
"인수가 잘못되었거나 잘못된 속성이 할당 잘못된 번호가"이것은 내가있어 코드입니다 말 :
Private Sub import_csv()
Dim file_name As String
Dim fnum As Integer
Dim whole_file As String
Dim lines As Variant
Dim one_line As Variant
Dim num_rows As Long
Dim num_cols As Long
Dim the_array() As String
Dim imported_array() As String
Dim txt As String
Dim R As Long
Dim C As Long
file_name = "test.csv"
'load the file
fnum = FreeFile
Open file_name For Input As fnum
whole_file = Input$(LOF(fnum), #fnum)
Close fnum
'Break the file into lines
lines = Split(whole_file, vbCrLf)
'Dimension the array
num_rows = UBound(lines)
one_line = Split(lines(0), ",")
num_cols = UBound(one_line)
ReDim the_array(num_rows, num_cols)
ReDim imported_array(num_rows, num_cols)
'Copy the data into the arrays
For R = 0 To num_rows
If Len(lines(R)) > 0 Then
one_line = Split(lines(R), ",")
For C = 0 To num_cols
imported_array(R, C) = one_line(C)
txt = one_line(C)
txt = replace(txt, " ", "-") '<----- problem line
the_array(R, C) = txt
Next C
End If
Next R
End Sub
"replace"라는 함수를 정의 했습니까? 이미 VBA에서 그 이름을 가진 메소드가 있습니다 ... –
나는 문제가 무엇인지 알아 냈다고 생각합니다. VBA.Replace를 사용해 보았는데 효과가있었습니다. 그래서 참조를 거쳤으나 누락 된 것을 찾지 못했습니다 :/ –