WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with Excel
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Add Comment Excel


Question:

How to add comment to a specific cell and also change the comment window size in Excel? Thanks in advance.

Answer:

Begin by recording a macro in Excel (TOOLS menu) and then doing all the actions by hand, then shutting the recording. Then go back in and view the recorded macro. Here is an example macro:
Sub Macro1()
'
Range("F3").Select
Range("F3").AddComment
Range("F3").Comment.Visible = False
Range("F3").Comment.Text Text:="(Width)(Length)"
Selection.ShapeRange.ScaleWidth 1.58, msoFalse, msoScaleFromTopLeft
Selection.ShapeRange.ScaleHeight 0.22, msoFalse, msoScaleFromTopLeft
Range("F3").Select
End Sub

Here is an attempt at translating the code to WinBatch:

;!! UNDEBUGGED !!

XLS =  "c:\temp\Data\sample2.xls" ; !!! CHANGE TO FIT YOUR NEEDS !!!

objXL=ObjectOpen("Excel.Application")
objXL.Visible=@TRUE ;Change to @FALSE to hide
objXL.UserControl=@TRUE
objWBK=objXL.Workbooks
objWBK.Open(XLS)

objRange=objXL.Range("F3")

objRange.AddComment
objComment = objRange.Comment
objComment.Visible = @TRUE ;Change to @FALSE to hide
objComment.Text(:: Text="(Width)(Length)")

msoFalse = 0
msoScaleFromTopLeft = 0
objShape =  objComment.Shape
objShape.ScaleWidth(1.58, msoFalse, msoScaleFromTopLeft)
objShape.ScaleHeight(0.22, msoFalse, msoScaleFromTopLeft)

Pause("Debugging","Caheck that the changes were made")

objXL.Quit

ObjectClose(objShape)
ObjectClose(objComment)
ObjectClose(objRange)
ObjectClose(objWBK)
ObjectClose(objXL)


Article ID:   W16101
File Created: 2004:03:30:15:42:52
Last Updated: 2004:03:30:15:42:52