Hi All,
I'm very new to the world of programming and now I'm currently having difficulties. I'm current tasked by my manager to create a VBScript that would 'disperse' or 'split' an excel file with lots of worksheet in it, and after that saving the new individual excel files into a new folder in the same directory as the source Excel file that was being 'splitted'.
The 'splitting' part of the excel file is fine, but the problem comes in when i want to create the folder. I can only get it running when i insert a path in the script. I don't want it this way because this vbs file will be shared among a lot of people in the office and they will all use it.
So my question is that is there a way for me to create the folder, in such a way that everyone in the office can use this VBScript and it will be saved inside the same directory as the source Excel file that they are 'splitting'? Below would be the script.
Option ExplicitDim sSrc, oWB, oWS, objFSO, strFolder
Set objFSO = CREATEOBJECT("Scripting.FileSystemObject")
strFolder = "C:\Users\Farhan Bin Bahrin\Desktop\test" ' this is where the problem is
objFSO.CreateFolder strFolder
With CreateObject("Excel.Application")
.ScreenUpdating = False
.Visible = False
.DisplayAlerts = False
For Each sSrc in WScript.Arguments
On Error Resume Next
Set oWB = .Workbooks.Open(sSrc)
On Error Goto 0
If .Workbooks.Count > 0 Then
For Each oWS in oWB.Sheets
oWS.Copy
.WorkBooks.Item(2).SaveAs strFolder & "\" & oWS.Name & ".xls"
.WorkBooks.Item(2).Close
Next
oWB.Close
End If
Next
.Quit
End With