Solved

Save Xlsx to xlsm file that has multiple tabs

Posted on 2016-08-12
4
66 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

815 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now