0

I have some problem converting simples VB scripts (formating) into MATLAB:

VB script:

Range("A1").Select
Selection.Font.Italic = True
With Selection.Borders(xlEdgeBottom)
    .LineStyle = xlContinuous
End With

I tried:

xlswrite('test.xls',1,'A1');
Excel = actxserver('Excel.Application');
Excel.Workbooks.Open('test.xls');

Range = Excel.Range('A1');
Range.Font.Italic = True; % Doesnt work
Range.Border.Item('xlEdgeRight').LineStyle = 1; % Doesnt work

Excel.Visible = 1;

Any workaround? Thanks

1 Answer 1

1

The problem is probably this line:

Range = Excel.Range('A1');

Your Excel object is an Application object, which doesn't have a Range property. The VBA example you follow uses a (IMHO) poor practice of using the global default objects that are only available within the context of the application itself. You need to grab a reference to the Workbook returned by this call:

Excel.Workbooks.Open('test.xls');

After that, you need to get the worksheet from it's indexed Worksheets property, then get the Range from that. Also, "xlEdgeRight" is an enumeration member so external calls have to use the integer values for them instead of a string. You can replace xlEdgeRight with 10.

I know next to nothing about Matlab, but this is what the more explicit code would look like in VBA:

Dim book As Workbook, sheet As Worksheet, rng As Range

Set book = Application.Workbooks.Open("test.xls")
Set sheet = book.Worksheets("Sheet1")

Set rng = sheet.Range("A1")
rng.Font.Italic = True
rng.Borders.Item(10).LineStyle = 1

You should be able to get it from there.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.