Adding a scroll bar to a cell to scroll its contents.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is that possible? I have many cells with a sepcific height. If the
contents of the cell exceed the height I would want a scrollbar to appear for
the cell....

Or does anyone have an alternative solution to this?
 
This might be a very crude solution but maybe it would give you an idea.

Add a textbox to the worksheet and name it as TextBox1. Then paste this
code in the worksheet code module:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Cells.Count > 1 Then Exit Sub

TextBox1.Left = Target.Left
TextBox1.Top = Target.Top
TextBox1.Width = Target.Width
TextBox1.Height = Target.Height
TextBox1.MultiLine = True
TextBox1.ScrollBars = fmScrollBarsVertical
TextBox1.LinkedCell = Target.Address

End Sub
 
This might be a very crude solution but maybe it would give you an idea.

Add a textbox to the worksheet and name it as TextBox1. Then paste this
code in the worksheet code module:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Cells.Count > 1 Then Exit Sub

TextBox1.Left = Target.Left
TextBox1.Top = Target.Top
TextBox1.Width = Target.Width
TextBox1.Height = Target.Height
TextBox1.MultiLine = True
TextBox1.ScrollBars = fmScrollBarsVertical
TextBox1.LinkedCell = Target.Address

End Sub
 
That sounds like a good idea.... I didnt even t hink about using text
boxes...thanks
 
How would that idea work in C#? I'm having some issues trying to find where
the multiline and scrollbars properties for a text box exist in C#
 
I'm not familiar with C#, but in VB (and VBA), I am able to access the
TextBox directly as an object inside the worksheet. I assume it would be
similar in C#.

Here's how I would do it in VB. I replaced fmScrollBarsVertical with it's
integer value of 2.


Dim xlApp As New Excel.Application
Dim xlWb As Excel.Workbook
xlWb = xlApp.Workbooks.Open("C:\TEMP\Sample.xls")

With xlWb.Sheets("Sheet1")
.TextBox1.MultiLine = True
.TextBox1.ScrollBars = 2 'fmScrollBarsVertical
MsgBox(.textbox1.text)
End With

xlWb.Close(False)
xlApp.Quit()
 
by the way, this works with the assumption that the workbook already has a
textbox control named "TextBox1"....
 
Hi,
I have the same problem. I tried to use your code but I don't know how to
link it to the cell. Can we link this code to a specific cell?
Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top