Hi,
My VBScript below works perfectly fine but just silly thing I cant figure it out -- can anyone please help me to improve results?
Script meant to --
1) get all files from the specific folder -- works
2) Delete external connections on all of them -- works (thank to this site)
3) New file Save As with exisitng fName -- works
Only thing is this script randomly saves new file in different drives so I want to specify a folder name for it to save but where do I specify a folder name if I want to save as files to a different location? I suppose this is silly question but I tired many things however without sucess.
The Script:
MyDateFormat = Right("0" & Day(now), 2)& "-" &Right("0" & Month(Now), 2)& "-"&_
Year(now)
dir = "R:\Reports\1"
Set oExcel = CreateObject("Excel.Application")
Set fso = CreateObject("Scripting.FileSystemObject")
oExcel.Application.Visible = True
oExcel.DisplayAlerts = False
oExcel.AskToUpdateLinks = False
oExcel.AlertBeforeOverwriting = False
For Each file In fso.GetFolder(dir).Files
If LCase(fso.GetExtensionName(file)) = "xlsx" Then
fName = fso.GetBaseName(file)
Set oWorkbook = oExcel.Workbooks.Open(file)
Do While oExcel.ActiveWorkbook.Connections.Count > 0
oExcel.ActiveWorkbook.Connections.Item(oExcel.ActiveWorkbook.Connections.Count).Delete
Loop
oExcel.Activeworkbook.SaveAs fName & "_" &_
MyDateFormat &".xlsx"
oExcel.Activeworkbook.Close
oExcel.Quit
End if
Next
Set fso = Nothing
Set oWorkbook = Nothing
Set oExcel = Nothing
My VBScript below works perfectly fine but just silly thing I cant figure it out -- can anyone please help me to improve results?
Script meant to --
1) get all files from the specific folder -- works
2) Delete external connections on all of them -- works (thank to this site)
3) New file Save As with exisitng fName -- works
Only thing is this script randomly saves new file in different drives so I want to specify a folder name for it to save but where do I specify a folder name if I want to save as files to a different location? I suppose this is silly question but I tired many things however without sucess.
The Script:
MyDateFormat = Right("0" & Day(now), 2)& "-" &Right("0" & Month(Now), 2)& "-"&_
Year(now)
dir = "R:\Reports\1"
Set oExcel = CreateObject("Excel.Application")
Set fso = CreateObject("Scripting.FileSystemObject")
oExcel.Application.Visible = True
oExcel.DisplayAlerts = False
oExcel.AskToUpdateLinks = False
oExcel.AlertBeforeOverwriting = False
For Each file In fso.GetFolder(dir).Files
If LCase(fso.GetExtensionName(file)) = "xlsx" Then
fName = fso.GetBaseName(file)
Set oWorkbook = oExcel.Workbooks.Open(file)
Do While oExcel.ActiveWorkbook.Connections.Count > 0
oExcel.ActiveWorkbook.Connections.Item(oExcel.ActiveWorkbook.Connections.Count).Delete
Loop
oExcel.Activeworkbook.SaveAs fName & "_" &_
MyDateFormat &".xlsx"
oExcel.Activeworkbook.Close
oExcel.Quit
End if
Next
Set fso = Nothing
Set oWorkbook = Nothing
Set oExcel = Nothing