Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Create & Format XL Comments with VBA


XL2003

I'm trying to take the formatted text of a cell and put it into a
comment.

While it would be cool to format the colors, size and any other options
that goes with Edit Comment | Format Comment, I would be satisfied to
simply have the first line bold.

Example of Stock Codes:
Cell B1 = "*Local Stock:*
Parts are on-hand"
Cell B2 = "*Manufacturer Ship:*
Parts ordered are shipped
directly by Manufacturer" ... etc

I'm using SELECT CASE code to determine my stock code which in turns
points to the cell to be copied into the comment.

---------------
Select Case rcStr ' Evaluate Stock Code.
Case "A"
commentText = Index.Range("B1").Text
Case "B"...
commentText = Index.Range("B2").Text
Case "C"...etc
End Select

On Error Resume Next
ws.Cells(niinRow, 6).AddComment
With ws.Cells(niinRow, 6).Comment
..Visible = False
..Text Text:=commentText
..Shape.TextFrame.AutoSize = True
' code here to bold the first line, or
End With
' code here to bold the first line?
----------

So far, the code works fine in that it replicates the linebreaks as
entered on the source cells. I'm almost positive that I've seen an
example from somewhere a few years ago that handles formatting, but now
that I need it ...

I'm thinking this may involve using FIND, LEN and or LEFT to locate
where the first soft line break [Alt+Enter] and bold the string prior
to it. But I've got zilch from searching archives and experimenting in
this direction.

TIA


--
AH·C
------------------------------------------------------------------------
AH·C's Profile: http://www.excelforum.com/member.php...o&userid=29108
View this thread: http://www.excelforum.com/showthread...hreadid=496363

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Create & Format XL Comments with VBA

Use the characters object to format character by character or to format a
subset of characters.

For an illustration, turn on the macro recorder and then format individual
characters in a cells.

You can adapt it to your textframe as well.

--
Regards,
Tom Ogilvy


"AH·C" wrote in message
...

XL2003

I'm trying to take the formatted text of a cell and put it into a
comment.

While it would be cool to format the colors, size and any other options
that goes with Edit Comment | Format Comment, I would be satisfied to
simply have the first line bold.

Example of Stock Codes:
Cell B1 = "*Local Stock:*
Parts are on-hand"
Cell B2 = "*Manufacturer Ship:*
Parts ordered are shipped
directly by Manufacturer" ... etc

I'm using SELECT CASE code to determine my stock code which in turns
points to the cell to be copied into the comment.

---------------
Select Case rcStr ' Evaluate Stock Code.
Case "A"
commentText = Index.Range("B1").Text
Case "B"...
commentText = Index.Range("B2").Text
Case "C"...etc
End Select

On Error Resume Next
ws.Cells(niinRow, 6).AddComment
With ws.Cells(niinRow, 6).Comment
Visible = False
Text Text:=commentText
Shape.TextFrame.AutoSize = True
' code here to bold the first line, or
End With
' code here to bold the first line?
----------

So far, the code works fine in that it replicates the linebreaks as
entered on the source cells. I'm almost positive that I've seen an
example from somewhere a few years ago that handles formatting, but now
that I need it ...

I'm thinking this may involve using FIND, LEN and or LEFT to locate
where the first soft line break [Alt+Enter] and bold the string prior
to it. But I've got zilch from searching archives and experimenting in
this direction.

TIA


--
AH·C
------------------------------------------------------------------------
AH·C's Profile:

http://www.excelforum.com/member.php...o&userid=29108
View this thread: http://www.excelforum.com/showthread...hreadid=496363



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Create & Format XL Comments with VBA


Tom, thanks for pointing me in the right direction.

Took me a while to figure out what was part of which group, then more
time to tighten the code as much as possible.

Anyway, I hope others may find it useful -- save themselves some of the
hassle in solving this -- so here goes.
Note: -If there is a way to indent, I'm sorry . From the
VBE, I substitued the tabs with a PIPE & SPACE ("| ") in hopes of
maintaining some semblence of order, especially since there are nests
within nests.-

Sub AACode()
Set thisAACCount = Dash1.Range("G$15:G" & niinRow)
Dim aacStr As String, aacCell As Range, commentText As String,
thisAACCount As Range
| If Application.WorksheetFunction.CountIf(thisAACCount , Cells(niinRow,
7).Value) = 1 Then 'is value the 1st instance?
| | | 'then add and format comment
| | On Error Resume Next
| | Select Case aacStr ' Evaluate Stock Code.
| | | Case "A"
| | | | commentText = SheetMaster.Range("P67").Text
'=======Sample Text=====
'*NOT STOCKED, CENTRALLY PROCURED, LONG LEAD·*
'IMM/Service centrally managed but not stocked item. Procurement
' will be initiated only after receipt of a requisition.
'======End Sample Text===
| | | Case "B"
| | | | commentText = SheetMaster.Range("P68").Text
| | | Case "Z"
| | | | commentText = SheetMaster.Range("P92").Text
| | End Select
|
| | 'On Error Resume Next
| | Dim aacEOL As Long
| | aacEOL = Application.WorksheetFunction.Find("·", commentText, 1) '
to find position of the last char on 1st line -- see Sample Text above
| | Dash1.Cells(niinRow, 7).Comment.Delete 'Clear any comments
| | Dash1.Cells(niinRow, 7).AddComment
| | With Dash1.Cells(niinRow, 7).Comment
| | | .Visible = False
| | | .Text Text:=commentText
| | | With .Shape 'format entire comment
| | | | .Fill.Visible = msoTrue
| | | | .Fill.Visible = msoTrue
| | | | .Fill.Solid
| | | | .Fill.ForeColor.SchemeColor = 42 '42 = LightGreen, 27 =
LightTurquoise
| | | | .Fill.Transparency = 0#
| | | | .Line.Weight = 0.75
| | | | .Line.DashStyle = msoLineSolid
| | | | .Line.Style = msoLineSingle
| | | | .Line.Transparency = 0#
| | | | .Line.Visible = msoTrue
| | | | .Line.ForeColor.SchemeColor = 10
| | | | .Line.BackColor.RGB = RGB(255, 255, 255)
| | | | .TextFrame.MarginLeft = 3.6
| | | | .TextFrame.MarginRight = 3.6
| | | | .TextFrame.MarginTop = 3.6
| | | | .TextFrame.MarginBottom = 3.6
| | | | .TextFrame.AutoSize = True
| | | | .TextFrame.HorizontalAlignment = xlLeft
| | | | .TextFrame.VerticalAlignment = xlTop
| | | | .TextFrame.ReadingOrder = xlContext
| | | | .TextFrame.Orientation = xlHorizontal
| | | | .TextFrame.AutoSize = True
| | | | .TextFrame.HorizontalAlignment = xlLeft
| | | | .TextFrame.VerticalAlignment = xlTop
| | | | .TextFrame.ReadingOrder = xlContext
| | | | .TextFrame.Orientation = xlHorizontal
| | | | With .TextFrame.Characters.Font
| | | | | .Name = "Tahoma"
| | | | | .FontStyle = "Regular"
| | | | | .Size = 8
| | | | | .Strikethrough = False
| | | | | .Superscript = False
| | | | | .Subscript = False
| | | | | .OutlineFont = False
| | | | | .Shadow = False
| | | | | .Underline = xlUnderlineStyleNone
| | | | | .ColorIndex = 5 'Blue
| | | | End With
| | | | With .TextFrame.Characters(Start:=1, Length:=aacEOL).Font '1st
line is bold & darkblue
| | | | | .Name = "Arial"
| | | | | .FontStyle = "Bold"
| | | | | .ColorIndex = 11 'DarkBlue
| | | | End With
| | | End With
| | End With
| End If
|
| | 'Reformat Cell for hi-lite/emphasis
| If aacStr < "" Then 'True or False, if True...
| | aacStr = UCase(aacStr)
| | Select Case aacStr| ' Evaluate text.
| | | Case "B", "F", "L", "M", "N", "R", "S", "U", "W", "Y" ' "SPECIAL"
ACTIONS REQ'D. Cannot order w/o higher authorization
| | | With aacCell 'RED font on LIGHTYELLOW
| | | | .Font.Name = "Arial Black"
| | | | .Font.FontStyle = "Bold"
| | | | .Font.ColorIndex = 3
| | | | .Interior.ColorIndex = 19
| | | | .Interior.Pattern = xlSolid
| | | | .Interior.PatternColorIndex = 2
| | | End With
|
| | | Case "P", "T" ' "NO", absolutely cannot order, must find
alternative
| | | With aacCell 'YELLOW font on RED
| | | | .Font.Name = "Arial Black"
| | | | .Font.FontStyle = "Bold"
| | | | .Font.ColorIndex = 6
| | | | .Interior.ColorIndex = 3
| | | | .Interior.Pattern = xlSolid
| | | | .Interior.PatternColorIndex = 2
| | | End With
|
| | | Case "A", "O", "V", "X", "Z" ' "LONG LEAD", be prepared to wait
for delivery
| | | With aacCell 'BLUE font on LIGHTGREEN
| | | | .Font.Name = "Arial Black"
| | | | .Font.FontStyle = "Bold"
| | | | .Font.Size = 8
| | | | .Font.ColorIndex = 5
| | | | .Interior.ColorIndex = 20
| | | | .Interior.Pattern = xlSolid
| | | | .Interior.PatternColorIndex = xlAutomatic
| | | End With
| | End Select
| End If
| aacEOL = 0
| aacStr = ""
| commentText = ""
End Sub

Again, thanks a million. And have a Happy New Year!!!


--
AH·C
------------------------------------------------------------------------
AH·C's Profile: http://www.excelforum.com/member.php...o&userid=29108
View this thread: http://www.excelforum.com/showthread...hreadid=496363

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
excel 2000 how to format the comments font all comments Delquestion Excel Discussion (Misc queries) 1 October 8th 09 02:19 PM
Create Comments Vinod[_2_] Excel Worksheet Functions 1 November 6th 07 12:27 PM
format for comments De Excel Discussion (Misc queries) 2 March 23rd 07 06:39 PM
Comments Format Help David Excel Worksheet Functions 0 January 16th 07 12:14 PM
Create Excel sheet in HTML with comments Luke Webber Excel Programming 2 October 7th 03 02:34 PM


All times are GMT +1. The time now is 12:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"