指定一个范围的数,随机抽取其中一个数输入到一个表格中,然后循环这个步骤,因为有很多excel表格,下面这个代码是30-35之间的范围,不知道怎么搞的,批处理的时候所有填入的随机数都是一样的,我要怎么才能填入不一样的数- Dim x
- Randomize
- x= Int((35-30 * Rnd) + 30)
-
- Dim objSFO
- Dim objFolder
- Dim objFiles
- Dim objFile
- address="A1"
- Value=x
-
- set fso=createobject("scripting.filesystemobject")
- set excel=createobject("excel.application")
- Set objFolder = fso.GetFolder("C:\Users\Administrator\Desktop\新建文件夹 (4)")
- Set objFiles = objFolder.Files
- For Each objFile In objFiles
- If Right(objFile.Name, 4) = ".xls" Then
- excel.visible=false
- set w=excel.workbooks.open(objFile.path)
- excel.Sheets("sheet1").Range(address).Value=Value
- W.SAVE
- W.CLOSE
- End If
- Next
- MsgBox "完成。", vbInformation
复制代码
|