View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
ken ken is offline
external usenet poster
 
Posts: 21
Default "Comment" format anomaly

G'day there Peter T,

If the routine is in a normal module in the same and in the same workbook as
the change event there should be no problem to call it from the event code.
Put a break in the event on the line that calls the routine.


I've done a bit more work with it, and now I'm completely confused.

I still haven't got the routine to work, but I still don't know why.

I've put in error trapping, and there aren't any errors raised. I've
tried calling the formatting routine from various locations within the
comment writing code, with no result.

I have this in the sheet's module:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count = 1 Then
If InRange(Target, Me.Range("B10:B35")) Then
If Not Len(Target.Value) = 0 Then
Call enterOp(Target)
End If
End If
Call ChangeCommentFormat
End If
End Sub

But it doesn't matter where I put the ChangeCommentFormat call within
that code, it doesn't work. I've stepped through the CCF routine, and
it goes through each command but nothing happens. With that in mind, I
tried putting other commands in the "enterOp" routine (it copies a
hyperlink; changes the displayed text; inserts a comment and then sets
the comment text) and found that some of those don't work either. For
instance, the "enterOp" routine works with the selected cell as "rng"
with the hyperlink & comment being successfully inserted in the selected
cell. Having done that, I tried to use .Offset(0,1).select to move the
selection, after adding the comment but that didn't work. Using
Activesheet.Range("A1").select didn't work either. But debug.print and
msgbox "Test" worked as expected.

Stepping through the CCF routine when called from "enterOp" I used the
immediate window to see what I was working with. I found that typing "?
c.text" printed the comment to that window as expected, however "?
c.Shape.TextFrame.Characters.Font.bold" (which should be true or false)
gave the "Object doesn't have this property or method" error.

None of this makes any sense to me. I now have the formatting code
called from the Worksheet_Activate event which sort of works for my
purposes, but I can't understand why it won't work when called
otherwise. Nor why I can't select another cell by the using code.

Does anyone have any ideas?

Thanks for reading,
Ken McLennan
Qld, Australia