Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15079

vb script to open file and execute query in excel

$
0
0
In the below open file.xlsx, let the odbc query execute, save, and close. The code does execute but there will always only be one file.xlsx and a loop is currently running on a directory, that I can not seem to fix. The other issue is the wscript.sleep(20000) because what if the query needs longer, I can't seem to set that to not be a fixed time, rather let the query execute, save and close. Thank you :)



VB
Code:

Set fso = CreateObject("Scripting.FileSystemObject")
Set xl  = CreateObject("Excel.Application")
xl.Visible = True

For Each f In fso.GetFolder("C:\path").Files
 If LCase(fso.GetExtensionName(f.Name)) = "xlsx" Then
  Set wb = xl.Workbooks.Open(f.Path)
  wb.RefreshAll
  wscript.sleep(20000)
  wb.Save
  wb.Close
 End If
Next

xl.Quit


Viewing all articles
Browse latest Browse all 15079

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>