matlab - Excel Range object throws error 0x800A03EC because of a string longer than 255 characters -
using activex server matlab, trying highlight many cells in excel sheet @ once. these not in specific columns or rows use range('a1,b2,...')
access them. string accepted range object has less 255 characters or error:
error: object returned error code: 0x800a03ec
is thrown. following code reproduces error empty excel file.
hactx = actxserver('excel.application'); hwb = hactx.workbooks.open('c:\book1.xlsx'); hsheet = hwb.worksheets.item('sheet1'); col = repmat('a', 100, 1); row = num2str((1:100)'); %' cellind = strcat(col, strtrim(cellstr(row))); str1 = strjoin(cellind(1:66), ','); %// 254 characters str2 = strjoin(cellind(1:67), ','); %// 258 characters hsheet.range(str1).interior.color = 255; %// works hsheet.range(str2).interior.color = 255; %// error 0x800a03ec hwb.save; hwb.close(false); hactx.quit;
how can around this? found no other relevant method of calling range, or of otherwise getting cells want modify.
if start string
, can test length determine if range()
can handle it. here example of building diagonal range:
sub diagonalrange() dim bigstring string, bigrange range dim long, howmany long, ln string howmany = 100 = 1 howmany bigstring = bigstring & "," & cells(i, i).address(0, 0) next bigstring = mid(bigstring, 2) ln = len(bigstring) msgbox ln if ln < 250 set bigrange = range(bigstring) else set bigrange = nothing arr = split(bigstring, ",") each in arr if bigrange nothing set bigrange = range(a) else set bigrange = union(bigrange, range(a)) end if next end if bigrange.select end sub
for i = 10
, code the direct method, if code i=100
, array method used.
Comments
Post a Comment