I need to add a scrollbar to worksheet and link cell to it using Microsoft.Office.Interop.Excel library and C#.NET.
The correspoding VBA code is like this:
ActiveSheet.ScrollBars.Add(545.25, 172.5, 398.25, 24.75).Select
With Selection
.Value = 0
.Min = 0
.Max = 100
.SmallChange = 1
.LargeChange = 10
.LinkedCell = "$A$1"
.Display3DShading = True
End With
I tried the below code, it added Scrollbar but not working as expected and also unable to link cell to it.
oSheet.Shapes.AddOLEObject("Forms.ScrollBar.1", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, 545.25, 172.5, 398.25, 24.75);
My C#.NET Code adds scrollbar as an object to Excel, where as i need it as a control. It seems there is a difference in it.
Actual Result using my C#.NET code is attached as image below
But the Expected result is attached as image below:
I found the solution Here . Yes earlier I was adding ActiveX Object in place of Control. The below code works fine.
using Excel = Microsoft.Office.Interop.Excel;
:
:
Excel.ControlFormat Scrollbar = oSheet.Shapes.AddFormControl(Excel.XlFormControl.xlScrollBar, 545, 172, 398, 24).ControlFormat;
Scrollbar.Value = 0;
Scrollbar.Min = 0;
Scrollbar.Max=100;
Scrollbar.SmallChange = 1;
Scrollbar.LargeChange = 10;
Scrollbar.LinkedCell = "$A$1";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.