Changing the name of the sheet in excel

387 views (last 30 days)
I want to change the names of sheets in excel and then i need to perform the write operation on those sheets?
Is it possible to do with xlswrite?

Accepted Answer

Thomas Koelen
Thomas Koelen on 8 May 2015
You can use ActiveX directly from MATLAB:
xlswrite('test.xls',1) % # create test file
e = actxserver('Excel.Application'); % # open Activex server
ewb = e.Workbooks.Open('c:\test\test.xls'); % # open file (enter full path!)
ewb.Worksheets.Item(1).Name = 'new name'; % # rename 1st sheet
ewb.Save % # save to the same file
Be careful while testing, it overwrite the original file. Make a backup.
qing sheng
qing sheng on 27 Jan 2022
Hi! I am new to coding, when I using it in a for loop, it broke and warned me error code 0x800A01A8. So could you please find me a solution?

Sign in to comment.

More Answers (1)

Ilias Patsiaouras
Ilias Patsiaouras on 9 Sep 2019
Is this code portable for linux and Windows cause I think linux doesnt have ActiveX

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!