我如何获得一组复选框以留在使用VB代码移动到的位置? [英] How do I get a group of checkboxes to stay where they are moved to using vb code?

查看:140
本文介绍了我如何获得一组复选框以留在使用VB代码移动到的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Sheets(appServer & "chart").Select
ActiveChart.ChartTitle.Select
ActiveChart.ChartTitle.Text = appServer
ActiveChart.PlotArea.Select
Selection.Width = 434.944
ActiveChart.Legend.Select
ActiveChart.ChartArea.Select
ActiveChart.Legend.Select
Selection.Left = 466.86
Selection.Top = 62.544



这是我的代码,用于缩小图表的绘图区域,以便将图例移到上方,以便为复选框切换每个系列的显示留出空间.在我保存并重新打开程序之前,该程序运行良好.重新打开文件后,复选框会显示在图例的顶部,每次重新打开文件时我都可以轻松地解决该问题,但我只想在代码中解决该问题.在此先感谢您的帮助.



This is my code to shrink the plot area of a chart in order to move the legend over to make room for checkboxes to toggle the display of each series. The program works great until I save and reopen it. When it is reopened the checkboxes end up on top of the legend and I can easily fix that every time I reopen the file, but I would rather just fix the issue in my code.Thanks in advance for any help.

Dim chartRangeStart As Integer
Dim chartRangeEnd As Integer
Dim serverNum As Integer
Dim numOfServers As Integer
Dim topOfCheckbox As Integer
Dim appServerNum As Integer
Dim appServer As String

chartRangeStart = 51
chartRangeEnd = 98
numOfServers = 23
serverNum = 1
topOfCheckbox = 56
appServerNum = 0
appServer = server
   
   Do While serverNum <= numOfServers
' adds a checkbox for each appServer in an array
    ActiveChart.CheckBoxes.Add(4529766, 485607, 685185.75, 685896.75).Select
    Selection.Characters.Text = ServerNamesArray(appServerNum)
    Selection.ShapeRange.Fill.Visible = msoTrue
    Selection.ShapeRange.Fill.Solid
    Selection.ShapeRange.Fill.ForeColor.SchemeColor = 9
    Selection.ShapeRange.Fill.Transparency = 0#
    Selection.ShapeRange.Line.Weight = 0.75
    Selection.ShapeRange.Line.DashStyle = msoLineSolid
    Selection.ShapeRange.Line.Style = msoLineSingle
    Selection.ShapeRange.Line.Transparency = 0#
    Selection.ShapeRange.Line.Visible = msoFalse
      With Selection
        .Value = xlOff
        .LinkedCell = appServer & "!$" & ColumnArray(appServerNum) & "$2"
        .Display3DShading = False
      End With

' moves the checkbox to where I want it (until I save and reopen)
    Selection.ShapeRange.IncrementLeft 465#
    Selection.ShapeRange.IncrementTop topOfCheckbox
    Selection.ShapeRange.ScaleWidth 2#, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.ScaleHeight 1#, msoFalse, msoScaleFromTopLeft
    topOfCheckbox = topOfCheckbox + 13
     
    Loop



这是将复选框添加到图表的代码.



This is the code that adds the checkboxes to the chart.

推荐答案

"& ColumnArray(appServerNum)&
" & ColumnArray(appServerNum) & "


2" .Display3DShading = 错误 结束 使用 ' 将复选框移动到我想要的位置(直到我保存并重新打开) Selection.ShapeRange.IncrementLeft 465# Selection.ShapeRange.IncrementTop topOfCheckbox Selection.ShapeRange.ScaleWidth 2#,msoFalse,msoScaleFromTopLeft Selection.ShapeRange.ScaleHeight 1#,msoFalse,msoScaleFromTopLeft topOfCheckbox = topOfCheckbox + 13 循环
2" .Display3DShading = False End With ' moves the checkbox to where I want it (until I save and reopen) Selection.ShapeRange.IncrementLeft 465# Selection.ShapeRange.IncrementTop topOfCheckbox Selection.ShapeRange.ScaleWidth 2#, msoFalse, msoScaleFromTopLeft Selection.ShapeRange.ScaleHeight 1#, msoFalse, msoScaleFromTopLeft topOfCheckbox = topOfCheckbox + 13 Loop



这是将复选框添加到图表的代码.



This is the code that adds the checkboxes to the chart.


我知道这并不是您所要查找的,但是可以找到一个指定的Excel VSTO编程论坛.
I know this isnt exactly what you are looking for, but a designated forum for VSTO programming in Excel could be found here. I have at least been given answers there that I didnt get anywere else. Its worth a try anyway :)


这篇关于我如何获得一组复选框以留在使用VB代码移动到的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆