Function fails. What have I done wrong ?

AlexanderBB

Well-known Member
Joined
Jul 1, 2009
Messages
1,835
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Hi,
I reverse engineered a function that sets the text color in the first line of a comment.
I'm now trying to read that color back and failing.

Code:
Function GetCommentLineOneColor(ksheet, kAddr) As Variant
Dim r As Range, l As Integer
Set r = Worksheets(ksheet).Range(kAddr)
With r
    If Not .Comment Is Nothing Then
       l = InStr(.Comment.text, vbLf)
        With .Comment
           With .Shape
               Debug.Print .Characters(1, l).Font.Color
           End With
       End With
    End If
End With
End Function

I call this from the immediate window as
? GetCommentLineOneColor("Sheet1", "J116") where there's a comment in J116.

I'm getting Run-time error '438':
Object doesn't support this property or method
on the Debug.Print line.
Any help sorting this appreciated. Thanks :)
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
If you are tryng to modify a comment via a function called from a cell, it won't work. With a few arcane exceptions, a UDF can only return a value to the cell in which it appears.
 
Upvote 0
The Shape object doesn't have a Characters property. You need:
Rich (BB code):
With .Shape.TextFrame
 
Upvote 0
Shg, I'm trying to read it from a module. And Rory I got there just before your msg !!! then I struck a further problem
with it returning a color of Null. Managed to fix that with 'Debug.Print .Characters(1, l - 1).Font.Color"
I guess including the vblf casued that.

Many thanks, ABB
 
Upvote 0
You should also check that the Instr call doesn't return 0 before you try and use it.
 
Upvote 0

Forum statistics

Threads
1,214,986
Messages
6,122,611
Members
449,090
Latest member
vivek chauhan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top