Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Save Xlsx to xlsm file that has multiple tabs

Posted on 2016-08-12
4
Medium Priority
?
97 Views
Last Modified: 2016-08-31
I found this code to save xlsx to xlsm, it works great when there is only one sheet but I have files with multiple sheets and this vbs wont run. How do you modify this existing code to work with an excel file that has multiple tabs (sheets)?

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.SaveAs WScript.Arguments.Item(1), 52
oBook.Close False
oExcel.Quit

Open in new window

0
Comment
Question by:Culwatrnca11
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 57

Expert Comment

by:Bill Prew
ID: 41754300
I just tested it here, it works fine on multiple sheet file, what error or problem are you seeing?

~bp
0
 
LVL 57

Accepted Solution

by:
Bill Prew earned 2000 total points
ID: 41754305
I would suggest this change too, so that you don't have to specify the full path to the filenames on the command line if they aren't needed.  This will work better.

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

~bp
0
 

Author Closing Comment

by:Culwatrnca11
ID: 41778612
Thank you this worked..
0
 
LVL 57

Expert Comment

by:Bill Prew
ID: 41778702
Welcome, glad that was useful.

~bp
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question