Results 1 to 2 of 2

Thread: Format Comment IN Excel

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2002
    Posts
    70

    Format Comment IN Excel

    Hi Someone can help me ?

    I want format this comment using BOLD and COLOR

    Range("A1").Select
    Range("A1").AddComment
    Range("A1").Comment.Visible = False
    Range("A1").Comment.Text Text:="MRN:" & Chr(10) & "My Code"
    Range("A1").Select

    Thanks!

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    You can't do it using VBA so to speak. You may be able to do it
    by modifing the HTML/JavaScript code for comment.

    Code:
    SAMPLE CODE
    <![if !supportAnnotations]><style id="dynCom" type="text/css"><!-- --></style>
    
    <script language="JavaScript"><!--
    
    function msoCommentShow(com_id,anchor_id) {
    	if(msoBrowserCheck()) {
    	   c = document.all(com_id);
    	   a = document.all(anchor_id);
    	   if (null != c) {
    		var cw = c.offsetWidth;
    		var ch = c.offsetHeight;
    		var aw = a.offsetWidth;
    		var ah = a.offsetHeight;
    		var x = a.offsetLeft;
    		var y = a.offsetTop;
    		var el = a;
    		while (el.tagName != "BODY") {
    		   el = el.offsetParent;
    		   x = x + el.offsetLeft;
    		   y = y + el.offsetTop;
    		   }		
    		var bw = document.body.clientWidth;
    		var bh = document.body.clientHeight;
    		var bsl = document.body.scrollLeft;
    		var bst = document.body.scrollTop;
    		if (x + cw + ah/2 > bw + bsl && x + aw - ah/2 - cw >= bsl ) {
    		   c.style.left = x + aw - ah / 2 - cw; 
    		}
    		else {
    		   c.style.left = x + ah/2; 
    		}
    		if (y + ch + ah/2 > bh + bst && y + ah/2 - ch >= bst ) {
    	 	   c.style.top = y + ah/2 - ch;
    		} 
    		else {
    		   c.style.top = y + ah/2;
    		}
    		c.style.visibility = "visible";
    	   }
    	}
    }
    
    function msoCommentHide(com_id) {
    	if(msoBrowserCheck()) {
    	  c = document.all(com_id)
    	  if (null != c) {
    	    c.style.visibility = "hidden";
    	    c.style.left = "-10000";
    	    c.style.top = "-10000";
    	  }
    	}
    }
    
    function msoBrowserCheck() {
     ms=navigator.appVersion.indexOf("MSIE");
     vers = navigator.appVersion.substring(ms+5, ms+6);
     ie4 = (ms>0) && (parseInt(vers) >=4);
     return ie4
    }
    
    'HERE IS THE RELEVALANT CODE FOR FORMATTING THE COMMENT
    if (msoBrowserCheck()) {
    document.styleSheets.dynCom.addRule(".msocomspan1","position:absolute");
    document.styleSheets.dynCom.addRule(".msocomspan2","position:absolute");
    document.styleSheets.dynCom.addRule(".msocomspan2","left:-1.5ex");
    document.styleSheets.dynCom.addRule(".msocomspan2","width:2ex");
    document.styleSheets.dynCom.addRule(".msocomspan2","height:0.5em");
    document.styleSheets.dynCom.addRule(".msocomanch","font-size:0.5em");
    document.styleSheets.dynCom.addRule(".msocomanch","color:red");
    document.styleSheets.dynCom.addRule(".msocomhide","display: none");
    document.styleSheets.dynCom.addRule(".msocomtxt","visibility: hidden");
    document.styleSheets.dynCom.addRule(".msocomtxt","position: absolute");        
    document.styleSheets.dynCom.addRule(".msocomtxt","top:-10000");         
    document.styleSheets.dynCom.addRule(".msocomtxt","left:-10000");         
    document.styleSheets.dynCom.addRule(".msocomtxt","width: 33%");                 
    document.styleSheets.dynCom.addRule(".msocomtxt","background: infobackground");
    document.styleSheets.dynCom.addRule(".msocomtxt","color: infotext");
    document.styleSheets.dynCom.addRule(".msocomtxt","border-top: 1pt solid threedlightshadow");
    document.styleSheets.dynCom.addRule(".msocomtxt","border-right: 2pt solid threedshadow");
    document.styleSheets.dynCom.addRule(".msocomtxt","border-bottom: 2pt solid threedshadow");
    document.styleSheets.dynCom.addRule(".msocomtxt","border-left: 1pt solid threedlightshadow");
    document.styleSheets.dynCom.addRule(".msocomtxt","padding: 3pt 3pt 3pt 3pt");
    document.styleSheets.dynCom.addRule(".msocomtxt","z-index: 100");
    }
    
    // -->
    </script>
    <![endif]>
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width