[英]VB Script RefreshAll in folder (with exception)
edited to be more specific: 编辑更具体:
VBScript
below runs through entire folder, opens each *.XLSM file there , refreshes all data connections and saves updated files one by one. 下面的
VBScript
遍历整个文件夹, 在那里打开每个* .XLSM文件 ,刷新所有数据连接并逐个保存更新的文件。 Files are also password protected, but it's not that important. 文件也受密码保护,但并不重要。
How to enhance the code to AVOID files in folder, based on part or entire filename ? 如何根据部分或整个文件名增强文件夹中AVOID文件的代码? For an example avoid filenames ending with
z
however with still .xlsm
extension. 例如,避免使用以
.xlsm
扩展名结尾的以z
结尾的文件名。
Expected outcome for files located in the same folder: 位于同一文件夹中的文件的预期结果:
abc123.xlsm (refresh);
abc123.xlsm(refresh); abc123z.xlsm (avoid);
abc123z.xlsm(避免); file.xlsm (refresh);
file.xlsm(refresh); testz.xlsm (avoid)
testz.xlsm(避免)
Set fso = CreateObject("Scripting.FileSystemObject")
Set xl = CreateObject("Excel.Application")
xl.Visible = False
For Each f In fso.GetFolder("C:\test\").Files
If LCase(fso.GetExtensionName(f.Name)) = "xlsm" Then
Set wb = xl.Workbooks.Open(f.Path ,,,,,"x")
wb.RefreshAll
wb.Save
wb.Close
End If
Next
xl.Quit
you can try use split command. 你可以尝试使用split命令。
file_path =abc123.xlsm
file_name =split(file_path,".")
file_name is an array containing 2 values file_name是一个包含2个值的数组
file_name (0)=abc123 file_name(0)= abc123
file_name (1)=xlsm file_name(1)= xlsm
now you can check if the last char in file_name(0)="Z" 现在你可以检查file_name(0)=“Z”中的最后一个字符
if NOT(right(file_name(0),1)="Z") THEN
do...
ELSE
do...
END IF
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.