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. 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 ? For an example avoid filenames ending with z
however with still .xlsm
extension.
Expected outcome for files located in the same folder:
abc123.xlsm (refresh); abc123z.xlsm (avoid); file.xlsm (refresh); testz.xlsm (avoid)
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.
file_path =abc123.xlsm
file_name =split(file_path,".")
file_name is an array containing 2 values
file_name (0)=abc123
file_name (1)=xlsm
now you can check if the last char in file_name(0)="Z"
if NOT(right(file_name(0),1)="Z") THEN
do...
ELSE
do...
END IF
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.