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
Solved

Save Xlsx to xlsm file that has multiple tabs

Posted on 2016-08-12
4
75 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
  • 3
4 Comments
 
LVL 53

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 53

Accepted Solution

by:
Bill Prew earned 500 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 53

Expert Comment

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

~bp
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

856 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