We help IT Professionals succeed at work.

adding "ungroup sheets" to existing vbs code

339 Views
Last Modified: 2017-03-13
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,
Comment
Watch Question

Managing Director/Excel VBA Developer
CERTIFIED EXPERT
Distinguished Expert 2018
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
ShumsManaging Director/Excel VBA Developer
CERTIFIED EXPERT
Distinguished Expert 2018

Commented:
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

Culwatrnca11Data Analyst

Author

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'
ShumsManaging Director/Excel VBA Developer
CERTIFIED EXPERT
Distinguished Expert 2018

Commented:
Please paste your full code
Culwatrnca11Data Analyst

Author

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

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions