ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Crash on Mac with Office v. X: characters.insert (https://www.excelbanter.com/excel-programming/316043-crash-mac-office-v-x-characters-insert.html)

Christopher King

Crash on Mac with Office v. X: characters.insert
 
I am able to reproducibly crash Excel v. X running on a Mac (OS 10.1.5).
Can someone reproduce this behavior, and, if so, any ideas as to how to
avoid the problem?



To demonstrate, copy the code into Excel, enter, say, "asdfEasdf" in a cell,
and select the cell. Then run the FormatAnything procedure. As is, the
code won't cause a crash. It will replace the third character with "X".



Now uncomment the line that superscripts a character, and run the code
again. On my machine, Excel quits with a message saying that the system and
other applications were not damaged by the failure.



Sub FormatAnything()
' Various objects can be sent from here to "DoFormat", which
' formats the user's selection.



DoFormat Selection.Cells(1, 1) ' The "Cells" part is needed to
handle merged cells.

End Sub



Sub DoFormat(rTextObject As Object)



' Uncomment the following line to crash Word V. X SR1 on OS 10.1.5
'rTextObject.Characters(6, 1).Font.Superscript = True
rTextObject.Characters(3, 1).Insert ("X")

End Sub

One interpretation is that "Insert" causes the program to lose track of
where previously applied formatting was applied, resulting in the crash.



Chris King





Christopher King

Crash on Mac with Office v. X: characters.insert
 
By the way, I've never had any problem on a PC with this code. The code
also worked on a Mac using Office 98, and Office 2001. I've not tried it
with Office 2004.
Chris

"Christopher King" wrote in message
...
I am able to reproducibly crash Excel v. X running on a Mac (OS 10.1.5).
Can someone reproduce this behavior, and, if so, any ideas as to how to
avoid the problem?

To demonstrate, copy the code into Excel, enter, say, "asdfEasdf" in a

cell,
and select the cell. Then run the FormatAnything procedure. As is, the
code won't cause a crash. It will replace the third character with "X".

Now uncomment the line that superscripts a character, and run the code
again. On my machine, Excel quits with a message saying that the system

and
other applications were not damaged by the failure.

Sub FormatAnything()
' Various objects can be sent from here to "DoFormat", which
' formats the user's selection.

DoFormat Selection.Cells(1, 1) ' The "Cells" part is needed to
handle merged cells.

End Sub

Sub DoFormat(rTextObject As Object)

' Uncomment the following line to crash Word V. X SR1 on OS 10.1.5
'rTextObject.Characters(6, 1).Font.Superscript = True
rTextObject.Characters(3, 1).Insert ("X")

End Sub

One interpretation is that "Insert" causes the program to lose track of
where previously applied formatting was applied, resulting in the crash.

Chris King








All times are GMT +1. The time now is 10:02 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com