Sub Parse()
Workbooks.OpenText Filename:="C:\Users\karthic.rangaraj\Desktop\4401.csv"
' Parse it using comma and semicolon as delimiters
Range(Range("A1"), Range("A1").End(xlDown)).TextToColumns _
DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=True, Comma:=True, Space:=False, Other:=False, _
FieldInfo:= _
Array(Array(1, 2), Array(2, 2), Array(3, 2), Array(4, 1), Array(5, 2))
Range("B:B,D:D").Delete
'Range("D1").FormulaR1C1 = "Application_ID"
Dim lLR As Long
Dim vArray As Variant
Dim sString As String
'*****************************************************************************************
'Add as many items you like to this array
'*****************************************************************************************
vArray = Array("Windows XP", "Adobe", "IBM", "VLC", "PDFCreator", "Sonic", "Office", "Sigamtel", "Printer")
For i = LBound(vArray) To UBound(vArray)
sString = sString & Chr(34) & vArray(i) & Chr(34) & ","
Next i
'*****************************************************************************************
'This is the final array string that we pass to array formula
'*****************************************************************************************
sString = "{" & Left(sString, Len(sString) - 1) & "}"
lLR = Range("A" & Rows.Count).End(xlUp).Row
Range("D2").FormulaArray = "=INDEX(" & sString & ",1,MATCH(1,--ISNUMBER(SEARCH(" & sString & ",$C2,1)),0))"
Range("D2").AutoFill Destination:=Range("D2:D" & lLR)
ActiveWorkbook.SaveAs "C:\Users\karthic.rangaraj\Desktop\4401.xls", FileFormat:=56
' 52 = xlOpenXMLWorkbookMacroEnabled = xlsm (workbook with macro's in 2007)
End Sub
Я могу сохранить этот единственный файл как файл .xls, используя этот код
ActiveWorkbook.SaveAs "C:\Users\karthic.rangaraj\Desktop\4401.xls", FileFormat:=56
' 52 = xlOpenXMLWorkbookMacroEnabled = xlsm (workbook with macro's in 2007)
Вот мои вопросы:
Как получить доступ к куче файлов CSV в папке C:\Users\karthic.rangaraj\Desktop\CSVFiles
& Сохранить его как файл XLS в той же папке после того, как процесс выполняется с теми же именами файлов с использованием VBA?
У меня проблема с массивом:
Код:
vArray = Array("Windows XP", "Adobe", "IBM", "VLC", ".Net Framework", "Office", "Java", "Windows Media", "J2SE", "MSXML")
For i = LBound(vArray) To UBound(vArray)
sString = sString & Chr(34) & vArray(i) & Chr(34) & ","
Next i
sString = "{" & Left(sString, Len(sString) - 1) & "}"
lLR = Range("A" & Rows.Count).End(xlUp).Row
Range("D2").FormulaArray = "=INDEX(" & sString & ",1,MATCH(1,--ISNUMBER(SEARCH(" & sString & ",$C2,1)),0))"
Range("D2").AutoFill Destination:=Range("D2:D" & lLR)
если ввести более 10 элементов (скажем, 14), я получаю это сообщение об ошибке:
Unable to set the property of the class range FormulaArray
Что не так с формулой массива здесь?