adding "ungroup sheets" to existing vbs code

Found this code for converting XLSX to XLSM which works great on a different project. With this project when I open the excel file I need to "ungroup sheets" in the workbook then save_as xlsm. There are about 6 tabs total if that matters.

I execute it in the same directory as the excel file via a batch file:
start /min /wait "c:\Batch_Automation\xlsxtoxlsm.vbs" "C:\Batch_Automation\CCYY_MM_RUN_MMDDCCYY.xlsx" "C:\Batch_Automation\CCYY_MM_RUN_MMDDCCYY.xlsm"


Question: How do you add ungroup sheets to this code?
File name: XlsxToXlsm.vbs

------
if WScript.Arguments.Count < 2 Then
    WScript.Echo "Error! Please specify the source path and the destination. Usage: XlsxToxlsm SourcePath.xlsx Destination.xlsm"
    Wscript.Quit
End If
Dim oExcel
Set oExcel = CreateObject("Excel.Application")
Dim oBook
Set oBook = oExcel.Workbooks.Open(Wscript.Arguments.Item(0))
oBook.Worksheets(1).Activate
oBook.Worksheets(2).Activate
oBook.Worksheets(3).Activate
oBook.Worksheets(4).Activate
oBook.Worksheets(5).Activate
oBook.Worksheets(6).Activate


oBook.SaveAs WScript.Arguments.Item(1), 52
oBook.Close False
oExcel.Quit

Thank you,
Culwatrnca11Data AnalystAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ShumsDistinguished Expert - 2017Commented:
Hi,

Try activating just one worksheets instead of all.
If WScript.Arguments.Count < 2 Then
    WScript.Echo "Error! Please specify the source path and the destination. Usage: XlsxToxlsm SourcePath.xlsx Destination.xlsm"
    WScript.Quit
End If
Dim oExcel
Set oExcel = CreateObject("Excel.Application")
Dim oBook
Set oBook = oExcel.Workbooks.Open(WScript.Arguments.Item(0))
oBook.Worksheets(1).Activate
oBook.Worksheets(2).Activate
oBook.Worksheets(3).Activate
oBook.Worksheets(4).Activate
oBook.Worksheets(5).Activate
oBook.Worksheets(6).Activate

If ActiveWindow.oBook.Worksheets.Count > 1 Then
    ActiveWindow.oBook.Worksheets(1).Select
End If

oBook.SaveAs WScript.Arguments.Item(1), 52
oBook.Close False
oExcel.Quit

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ShumsDistinguished Expert - 2017Commented:
another approach would be:
Dim oExcel
Dim oBook
Dim oFSO

If WScript.Arguments.Count < 2 Then
    WScript.Echo "Error! Please specify the source path and the destination. Usage: XlsxToxlsm SourcePath.xlsx Destination.xlsm"
    Wscript.Quit
End If

Set oExcel = CreateObject("Excel.Application")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oBook = oExcel.Workbooks.Open(oFSO.GetAbsolutePathName(Wscript.Arguments.Item(0)))
oBook.Worksheets(1).Activate
oBook.SaveAs oFSO.GetAbsolutePathName(WScript.Arguments.Item(1)), 52
oBook.Close False
oExcel.Quit

Open in new window

0
Culwatrnca11Data AnalystAuthor Commented:
Shums,

On the first solution I get script error..  line 18 char 1 error Object Required: 'activeWindow'

On the 2nd solution I get script error line 1 char 1 error type mismatch: 'im'
0
ShumsDistinguished Expert - 2017Commented:
Please paste your full code
0
Culwatrnca11Data AnalystAuthor Commented:
figured it out..   missed something in my cut and paste.   Thank you again
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.