ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] °ÊºA·s¼W UserForm ¤Î CommandButton «á ¦p¦ó¼gclickªº°Ê§@¡H

  1. Public obj As New Class1
  2. Sub Auto_Open()
  3. Dim MyForm As VBComponent
  4. For Each vbc In ThisWorkbook.VBProject.VBComponents
  5.    If vbc.Type = 3 Then 'Àˬdªí³æ¼Ò²Õ
  6.       If vbc.Name = "Test_Form1" Then Exit Sub '¦³¸Óªí³æ«h¸õ¥Xµ{§Ç
  7.    End If
  8. Next
  9. Set MyForm = ThisWorkbook.VBProject.VBComponents.Add(vbext_ct_MSForm) '·s¼Wªí³æ¼Ò²Õ
  10. With MyForm
  11.     .Properties("Caption") = "Test_Form" 'ªí³æ¼ÐÃD
  12.     .Name = "Test_Form1" 'ªí³æ¦WºÙ
  13.     With .Designer
  14.       With .Controls.Add("Forms.CommandButton.1") '·s¼W«ö¶s
  15.           .Top = 50
  16.           .Left = 100
  17.           .Height = 20
  18.           .Width = 20
  19.           .Caption = ">>"
  20.           .Name = "Move_Data"
  21.       End With
  22.       For i = 1 To 2
  23.       With .Controls.Add("Forms.Listbox.1") '²M³æ
  24.           .Top = 10
  25.           .Left = (i - 1) * 100 + 20
  26.           .Height = 120
  27.           .Width = 80
  28.           .Name = "MyList" & i
  29.       End With
  30.       Next
  31.     End With
  32.     With .CodeModule '¦bªí³æ¼Ò²Õ¤º·s¼Wµ{§Ç
  33.       .InsertLines 1, "Private Sub UserForm_Initialize()"
  34.       .InsertLines 2, "MyList1.List=array(1,2,3,4,5,6,7,8,9)"
  35.       .InsertLines 3, "Set obj.MyBut = Controls(""Move_Data"")" '±N«ö¶s¥[¤Jª«¥óÃþ§O
  36.       .InsertLines 4, "End Sub"
  37.     End With
  38. End With
  39. With ThisWorkbook.VBProject.VBComponents("ThisWorkbook").CodeModule '¼g¤JÃö³¬ÀÉ®×µ{§Çªºµ{¦¡½X
  40.   .InsertLines 1, "Private Sub Workbook_BeforeClose(Cancel As Boolean)" & Chr(10) & _
  41. "With ThisWorkbook" & Chr(10) & _
  42. ".VBProject.VBComponents.Remove .VBProject.VBComponents(""Test_Form1"")" & Chr(10) & _
  43. "n = .VBProject.VBComponents(""ThisWorkbook"").CodeModule.CountOfLines" & Chr(10) & _
  44. ".VBProject.VBComponents(""ThisWorkbook"").CodeModule.DeleteLines 1, n" & Chr(10) & _
  45. ".Save" & Chr(10) & _
  46. "End With" & Chr(10) & _
  47. "End Sub"
  48. End With
  49. 'OpenForm '¶}±ÒÀɮצ۰ʶ}±Òªí³æ
  50. End Sub
  51. Sub OpenForm()
  52. 'Test_Form1.Show 0 '¶}±Òªí³æ
  53. End Sub
½Æ»s¥N½X
¦^´_ 10# C.F


    À³¸Ó¬O§Aªºªí³æ¤w¸g¦s¦b¡A¦Ó§A¦b¤@¦¸°õ¦æ¸Óµ{§Ç¡A²£¥Í¦WºÙ½Ä¬ð
¸Õ¸Õ¬Ý
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

§Ú¤w¸g¤â°Ê±Nªí³æ²¾°£¡A¤´µM¬O¦p¦¹ ~~ ©Ò¥H§Ú ¤£ª¾¸Ó¦p¦ó§@ ~~

TOP

¦^´_ 12# C.F


   ¤â°Ê²¾°£ªí³æ«á¡A¦]°O¾ÐÅ餴¥¼ÄÀ©ñ¦¹ªí³æ
½Ð³s¦PThisworkbook¼Ò²Õ¤ºªº©Ò¦³µ{¦¡½X§R°£«á¦sÀÉ
§Y¥i°õ¦æAuto_Openµ{§Ç
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

°O¾ÐÅé°Ú ~~~ À³¸Ó¬O¦p±z©Ò»¡ ~~ ¦]¬° ³o°ÝÃD¤£¬O¨C¦¸µo¥Í ~~
¦ý¦³®É¬O³sÄòµo¥Í¡A¦³®É ¬O ³sÄò°õ¦æ¤]¤£·|µo¥Í ~~

¥t¥~´N¬O·Q½Ð¸û ~~ ¦pªG§Ú­n¨ú±o MyList2 ¤¤©Ò±o¨ìªº¶µ¥Ø¡A§Ú¦bSub Auto_Open() ¤¤
¸Ó¦p¦ó¨ú±o¡H

§Ú¥Î MyForm.Designer.Controls("MyList2") ¤£¯à¦¨¥\ ~~

TOP

Private Sub MyNewBtn2_Click()
        Dim i%
        Dim Get_Item1
   
        With Test_Form3
               
             MsgBox .Item_GetList.ListCount
            
             If .Item_GetList.ListCount <> 0 Then
                                 ReDim Get_Item1(.Item_GetList.ListCount - 1) As String
                 For i = 0 To .Item_GetList.ListCount - 1
                     Get_Item1(i) = .Item_GetList.List(i)
                     MsgBox Get_Item1(i)
                 Next i
             End If
            
            
        End With
End Sub      
        §Ú·s¼W¤F¤@­Ó Button ¨ú±o¤F ListBox ªº­È¡A¦ý§Ú­n¦p¦óÅýuserform Ãö³¬ ¥BÅý
         ­ì¨Óªº Sub Auto_Open() Ä~Äò©¹¤U¶]~¡H

TOP

¤£¦n·N«ä¡A«á¨Ó¸Õ¤F Unload Test_Form3 ´N¥i¥HÃö¤F  ~~
¥i¬O§Ú­n¦p¦ó ªð¦^­ì¨Óªº Sub Auto_Open() ®É¡A§Ú¦p¦ó¨ú±o Item_GetList ùتº¨º¨Ç¶µ¥Ø°Ú¡H

TOP

¦^´_ 8# Hsieh


    ·Q½Ð°Ý ¦b·s¼WCommandButton ¤§«á

    ³oÃä¬O·s¼WButtonªº«ö¶s¨Æ¥ó¶Ü¡H
    With .CodeModule '¦bªí³æ¼Ò²Õ¤º·s¼Wµ{§Ç
      .InsertLines 1, "Private Sub UserForm_Initialize()"
      .InsertLines 2, "MyList1.List=array(1,2,3,4,5,6,7,8,9)"
      .InsertLines 3, "Set obj.MyBut = Controls(""Move_Data"")" '±N«ö¶s¥[¤Jª«¥óÃþ§O
      .InsertLines 4, "End Sub"
    End With

   ¨º°£¤F³o­Ó¤èªk¥~¯à¥Î¨ä¥Lªº¤èªk¥h·s¼W«ö¶sªº¨Æ¥ó¡H

TOP

¦^´_ 17# wanmas
¦]¬°¦¹°ÝÃD¬O±q·s¼Wªí³æ¶}©l
¦¹¬qµ{§Ç¬Oªí³æ¼Ò²Õªºªì©l¤Æµ{§Ç
¥Øªº¦b·íªí³æ¶}±Ò®É±Nªí³æ¤ºª«¥óªº³]©w¥[¤J
­Ó¤H¨Ã¤£«Øij¨Ï¥Î³o¼Ëªº¤èªk¾Þ§@ªí³æ
VBA¨Æª«¥ó¾É¦Vªºµ{¦¡»y¨¥
°£«D¯S§O¥Øªº¡A§_«hÀ³¥ý±Nª«¥ó³£³]¸m¦n
¨Ã¥B¨C­Óª«¥ó©Ò»Ýªºµ{§Ç¹w¥ý¼g¦n
©¡®É¥u»Ý±Ò°Êªí³æ§Y¥i°õ¦æ
³o¼Ë¦bµ{¦¡¼¶¼g¤¤¤ñ¸û®e©ö°»¿ù»P­×¥¿
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

§Úªº°ÝÃD¤ñ¸û²³æ¤@ÂI¡Aµ{¦¡ªº¥Øªº¬O¦b¬J¦³ªºªí³æ(UserForm3)¡A·s¼W3­ÓTextBox¡AµM«á¨C­ÓTextBox¥i¥H°õ¦æfunction(y_m_dinput (A)¡AÅܼƬ°A)¡Aµ{¦¡½X¦p¤U:
For X2 = 1 To 3
Set theTextBox = UserForm3("frame1").Controls.Add("Forms.TextBox.1", "TextBox" & TeCount + X2, True)
  With theTextBox
     .Name = "TextBox" & TeCount + X2
     If X2 = 1 Then
     .Left = 210
     ElseIf X2 = 2 Then
     .Left = 384
     Else
      .Left = 492
     End If
     .Width = 60
     .Top = K2 + 18
    myName = "Userform3"
    With ThisWorkbook.VBProject.VBComponents(myName).CodeModule
     '.DeleteLines 1, .countoflines
      Test = .countoflines - 44
     .insertlines Test, "Private Sub TextBox" & TeCount + X2 & "_Change()"
     .insertlines Test + 1, "A =" & TeCount + X2
     .insertlines Test + 2, "y_m_dinput (A)"
     .insertlines Test + 3, "End sub"
    End With
  End With
Next X2
µ{¦¡ªºµ²ªG¥i¥H¶]¥X3­ÓTextBox¡A¤]¥i¥H¼g¤F¥X¬Û¹ïÀ³ªºµ{§Ç¡A¦ý¬O´N¬OµLªk°õ¦æfunction.
½Ð°Ý°ÝÃD¥X¦b­þ??

TOP

        ÀR«ä¦Û¦b : ¦h°µ¦h±o¡C¤Ö°µ¦h¥¢¡C
ªð¦^¦Cªí ¤W¤@¥DÃD