Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PLEASE HELP!!!!! Can anyone tell me what this script does please

Status
Not open for further replies.

Mongrel99

IS-IT--Management
Feb 9, 2021
3
US
Set fs = CreateObject("Scripting.FileSystemObject")
Set rootFolder = fs.GetFolder(fs.GetParentFolderName(wscript.ScriptFullName))
Set oExcel = CreateObject("Excel.Application")

oExcel.Visible = True
oExcel.DisplayAlerts = False
oExcel.AskToUpdateLinks = False
oExcel.AlertBeforeOverwriting = False


For Each file in rootFolder.Files
If inStr(file.type, "Excel") > 0 Then
Set oWorkbook = oExcel.Workbooks.Open(file.path)
oWorkbook.RefreshAll
oExcel.CalculateUntilAsyncQueriesDone
oWorkbook.Save

oExcel.ActiveWorkbook.SaveAs "\\hccufile1\public\COVID19\IRS Treasury Refunds\IRS Treasury Refund Report.xlsx"

oWorkbook.Close
Set oWorkbook = Nothing
End If
Next

oExcel.Quit
Set oExcel = Nothing

Dim oFSO, myFolder
Dim xlCSV

myFolder="\\hccufile1\public\IT SYSTEMS\ITS PUBLIC\SQL Querys\IRS Treasury Refund\"


Set oFSO = CreateObject("Scripting.FileSystemObject")
xlCSV = 6 'Excel CSV format enum
Call ConvertAllExcelFiles(myFolder)
Set oFSO = Nothing


Sub ConvertAllExcelFiles(ByVal oFolder)
Dim targetF, oFileList, oFile
Dim oExcel, oWB, oWSH

Set oExcel = CreateObject("Excel.Application")
oExcel.DisplayAlerts = False
Set targetF = oFSO.GetFolder(oFolder)
Set oFileList = targetF.Files
For Each oFile in oFileList
If (Right(oFile.Name, 4) = "xlsx") Then
Set oWB = oExcel.Workbooks.Open(oFile.Path)
For Each oWSH in oWB.Sheets
Call oWSH.SaveAs ("\\hccufile1\public\IT SYSTEMS\ITS PUBLIC\SQL Querys\IRS Treasury Refund\History\IRS Treasury Refund Report_" & Month(Now)&"." & Day(Now)&"." & Year(Now) & ".csv", xlcsv)
Next
Set oWSH = Nothing
Call oWB.Close
Set oWB = Nothing
End If
Next
 
In general:
- search for excel files in folder A,
- open each workbook, refresh, save, save in folder B,
- start to process excel files in Folder C,
- open file by file, loop through sheets, save sheets as csv in folder D.

In fact the same file names are used in saving, so one excel file and one csv file are saved in B and D respectively.

combo
 
Thank you! I am new to vbscripts and is a little confusing trying to figure it out. Any advise where I can learn vbscripting easily and quickly? LOL...I know, I know, its a long shot.
 
Most of the code works with excel object model. Experience in working in excel with VBA would be helpful here, excel vba help concerning its properties and methods is available in VBE object browser via F1 key. VBscript syntax is a simplified version of classic VB and VBA.

combo
 
Thank you for your time in trying to explain the script to me. Is there any way you could explain what the script is doing per paragraph? Reason being, I need to identify what this script does because there are other scripts that are very similar to this one. So if I know what this one is doing then I will know what the others are doing as well. Your first explanation where you indicated A, B, C, D I got a little confused. If you are unable to explain by each paragraph, I understand. Any help you give is very appreciated!
 
Your script works with two libraries, Scripting and Excel. I would suggest to use excel VBE to examine objects. Excel is referenced by default, you can get help from object browser, by selecting object, property or method and hitting F1. You can reference Microsoft Scripting Runtime te inspect Scripting library. You can search web for actions used.

A: returned by [tt]wscript.ScriptFullName[/tt]. First hit by Google search for this command:
[pre]Syntax:
WScript.ScriptFullName
The ScriptFullName property is read only and returns the full path to the script currently being executed.[/pre]
in
Mongrel99 said:
I need to identify what this script does because there are other scripts that are very similar to this one.
IMHO you either need to employ a programmer or DIY and learn a bit VBS or VBA, go through the script line by line and understand each. It will be easier to understand the rest if the other scripts are similar.

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top