2014-04-15 3 views
0

각 시트에 단일 쿼리가 포함 된 Excel에서 데이터를 가져 오려고합니다.VB 스크립트 조인 함수에서 형식 불일치 오류가 발생했습니다.

그래서, 여기 내 단계는 다음과 같습니다


1) 엑셀 응용 프로그램을 만드는 -> 통합 문서 -> 워크 시트
2) (i '를하는 특정 시트에 모든 시트 이름과 포인트를 얻을 개체 m은 변형
(4)의 배열에 시간 임)
3) 시트의 모든 행을 검색위한 harcoded 일) 마지막 단일 문자열

내가 수하지 않다 마지막 단계로 각 배열 변형 합류 이루다. 배열에 25 조의 elemets init이 있거나 배열에 조인 함수를 사용하면 형식 불일치 오류가 발생합니다.

내 Excel에서 쿼리는 항상 첫 번째 열 자체에 여러 행에 배치됩니다.

시트 이름과 실제 쿼리 값에 대한 배열 변수에 데이터를 가져 오려면 사용자 정의 푸시 기능을 사용하고 있습니다. 내 배열을 동적으로 증가 시키길 원합니다. 값의.

ReDim arrSheetNames(-1) 

ReDim k(-1) 

Dim strQry() 


'create an excel application object 
set myExcel =CreateObject("Excel.Application") 

'create an excel workbook object 
set myWorkBook=myExcel.WorkBooks.Open("D:\Test.xlsx") 


'Get the sheetnames into an array 
For i = 1 To myWorkBook.Sheets.Count 
    fnPush arrSheetNames, myWorkBook.Sheets.Item(i).Name 
Next 


'Get th second sheet of the excel 
set mysheet = myworkbook.Worksheets(arrSheetNames(0)) 


'Get the max row occupied in the excel file 
Row=mysheet.UsedRange.Rows.Count 

'Get the max column occupied in the excel file 
Col=mysheet.UsedRange.columns.count 


'To read the data from the entire Excel file 
For i= 1 to Row 
    For j=1 to Col 
     fnPush k,mysheet.cells(i,j).value 
    Next 
Next 


m = join (arrSheetNames) 
msgbox m 


this is where im getting only 25 rows added to the string however there are 33 elements  in the array k. 

i=0 
' 
For i = 0 To UBound(k) Step 1 
n = n & k(i) 
Next 

msgbox n 


when i'm using this statement it's throwing an error for type mismatch 
strQry = join(k) 


msgbox strQry 



'Save the Workbook 
'myExcel.ActiveWorkbook.Save 

'Close the Workbook 
myExcel.ActiveWorkbook.Close 

'Close Excel 
myExcel.Application.Quit 

Set mysheet =nothing 
Set myWorkBook = nothing 
Set myExcel = nothing 


sub fnPush(arr, var) 
    dim uba 
    uba = UBound(arr) 
    redim preserve arr(uba+1) 
    arr(uba+1) = var 
end sub 
+0

문자열의 길이는 25 개뿐입니다. – brettdj

+0

죄송합니다. 문자를 표시 할 때 MSGBOX 제한 사항에 문제가있는 것 같습니다. 내 문자열이 모든 요소를 ​​받고 있지만 msgbox 프롬프트 제한이 배열의 25 번째 항목에 도달했습니다. – user3534583

답변

0

의 VBScript의 MsgBox 기능은 1023 자까지 표시 할 수 있습니다 :

아래에있는 내 코드를 찾을하시기 바랍니다. join() 성명서로 그 한계에 도달하고 계신 것 같습니다.

0

Dim strQry()Dim strQry으로 바꾸십시오. 그렇지 않으면 오류가 발생한 배열에 조인 결과 문자열을 할당해야합니다.

관련 문제