How to fix activeX checkboxes moving when opening file

给你一囗甜甜゛ 提交于 2019-12-12 01:55:27

问题


I know this question have been ask before but I did not find a good answer for me. I can't do the windows updates because this form is used on multiple computers all across the country.

I have 24 checkboxes that are hidden by default and them become visible depending on the combobox value. If I save the file with the checkboxes being hidden, once I open it all the checkboxes will be at one spot(not where they are suppose to be). If I save it with the checkboxes being visible then I open it everything work perfectly fine.

This is the bad one

This is the good one

The only way that I got it to work is if I save it with all the checkboxes being hidden then I hide them when workbook is open. This could be a problem if the user does not save it properly. Like this

 'if the row the row is hidden then the 2 checkboxes on this row are hidden too
 ActiveSheet.Rows("54:101").Hidden = False

 'Hide rows 54 to 101
 ActiveSheet.ComboBox2.Value = ""
 ActiveSheet.ComboBox3.Value = ""

I tried changing the object positioning property of the checkboxes but it seems like it has to be Move but don't size with cells for it to work


回答1:


I fixed it myself. My solution is to set a location to a cell for every checkbox like so

Dim rng As Range
Set rng = ActiveSheet.Range("H65")
With ActiveSheet.OLEObjects("CheckBox223")
    .Top = rng.Top
    .Left = rng.Left
    .Width = rng.Width
    .Height = rng.RowHeight
End With

 Set rng = ActiveSheet.Range("J65")
 With ActiveSheet.OLEObjects("CheckBox224")
    .Top = rng.Top
    .Left = rng.Left
    .Width = rng.Width
    .Height = rng.RowHeight
End With

 Set rng = ActiveSheet.Range("H69")
 With ActiveSheet.OLEObjects("CheckBox221")
    .Top = rng.Top
    .Left = rng.Left
    .Width = rng.Width
    .Height = rng.RowHeight
End With

 Set rng = ActiveSheet.Range("J69")
 With ActiveSheet.OLEObjects("CheckBox222")
    .Top = rng.Top
    .Left = rng.Left
    .Width = rng.Width
    .Height = rng.RowHeight
End With

 Set rng = ActiveSheet.Range("H73")
 With ActiveSheet.OLEObjects("CheckBox219")
    .Top = rng.Top
    .Left = rng.Left
    .Width = rng.Width
    .Height = rng.RowHeight
End With

 Set rng = ActiveSheet.Range("J73")
 With ActiveSheet.OLEObjects("CheckBox220")
    .Top = rng.Top
    .Left = rng.Left
    .Width = rng.Width
    .Height = rng.RowHeight
End With


来源:https://stackoverflow.com/questions/29146791/how-to-fix-activex-checkboxes-moving-when-opening-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!