Avatar of Culwatrnca11
Culwatrnca11
Flag for United States of America asked on

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,
Microsoft OfficeVB ScriptVBAMicrosoft ExcelVisual Basic Classic

Avatar of undefined
Last Comment
Culwatrnca11

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Shums Faruk

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Shums Faruk

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

Culwatrnca11

ASKER
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'
Shums Faruk

Please paste your full code
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Culwatrnca11

ASKER
figured it out..   missed something in my cut and paste.   Thank you again