定义全局变量 const a = "dota" function test() {Debug.Print(a) } 获取表格中单元格内容 function test() {Debug.Print("第一行第二列",Cells(1,2).Text)Debug.Print("A1:",Range("A1").Text) } 写单元格 Range("C1").Value2 = "qwerb"//把C1单元格写入qwerb 遍历表格 function a() {var r = Range("A1:C2")for( i of r){Debug.Print(i.Text)} } 遍历文件夹下excel文件并打开 //注意写路径的时候要用\\进行转义否则会报错,文件夹路径最后也要写两个\否则无法打开文件 const path = "E:\\T\\" function test() {var fileName = Dir(path + "*.xlsx")//此处用*.xlsx来过滤excel文件,也可以用其他的表达式来过滤文件,字符串的组合可以用+来串联//如果想指定某个文件打开可以直接写成 Workbooks.Open("E:/T/新建 XLSX 工作表 (3).xlsx", undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, true);while(fileName != ""){Debug.Print(fileName)Workbooks.Open(path + fileName, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, true);fileName = Dir()} }