问题
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 oneThe 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