VBScript Excel问题

0 vbscript excel

我制作了一个将Excel文件读入Dictionary对象的vbs脚本.当我运行脚本时它不会做任何事情.没有错误消息.

这是代码:

Set objWords = CreateObject("Scripting.Dictionary")
objWords.CompareMode = 1

CurPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open(CurPath & "/RE Glossary.xls")
Set objWorksheet = objExcel.ActiveWorkBook.WorkSheets("MG")


intRow = 1

Do Until (objExcel.Cells(intRow, 1).Value) = ""
    Value1 = (objExcel.Cells(intRow, 1).Value)
    Value2 = (objExcel.Cells(intRow, 2).Value)
    objWords.item(Value1) = Value2
Loop

objExcel.Quit

msgbox "There are " & objWords.Count & " words in the glossary."

word = inputbox("word")
if objWords.exists(word) then
    msgbox word & vbnewline & "------------" & vbnewline & objWords.item(word)
else
    msgbox word & " is not in the glossary."
end if
Run Code Online (Sandbox Code Playgroud)

HRg*_*ger 6

你不需要加入intRow = intRow + 1循环吗?

intRow = 1
Do Until (objExcel.Cells(intRow, 1).Value) = ""
    Value1 = objExcel.Cells(intRow, 1).Value
    Value2 = objExcel.Cells(intRow, 2).Value
    objWords.item(Value1) = Value2
    intRow = intRow + 1
Loop
Run Code Online (Sandbox Code Playgroud)