返回列表 上一主題 發帖

請問我這VBA哪裡有問題?為什麼會無法出現 424 無法找到物件呢?

回復 20# jeffrey628litw

F15儲存格是故意不放圖片要測試撈不撈的出預設的圖片(沒有圖片)
那圖片就依續放在Image1, Image2,Image3,Image4 中 Image3 是沒有圖片的

修改後是將三個有圖片連續放在Image1, Image2,Image3 ,Image4 是沒有圖片的
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 21# GBKEE


    G大  版主您好:
    1.就依照您說的方式,可以幫我那樣改嗎?

     然後我又有2個問題需要您幫忙我:

    2.
       2-1.可以新增1個Combobox2 ,然後篩選工作表 Datababse   "J欄"不重複資料,例如 BGS、PSA、沒鑑定。
       2-2.然後這個Combobox2可以如果Combox1 篩選名字後,如Michael Jordan,然後再篩選Combobox2選BGS後出現圖片

    3.然後因為篩選後會超過4張Image,所以要製作分頁篩選,這可以用Combobox3製作嗎?如圖中右上方所示



雲端檔案:http://webhd.xuite.net/_oops/jeffrey628litw/k03

    感謝G大 版主。

TOP

回復 22# jeffrey628litw
3.然後因為篩選後會超過4張Image
ComboBox1 右邊新增一ComboBox3
ComboBox2 右邊新增一ComboBox4
  1. Option Explicit                  '強制 模組的變數必須要 Dim的宣告,會使程式易於偵錯
  2. '模組頂端上 Dim的變數 可在UserForm1的全部程式中使用
  3. Dim Sh(1 To 2) As Worksheet, D As Object, D1 As Object, xTempPicture As String
  4. Dim AR_Image(), AR_TexTbox(), AR_Label(), xName As String
  5. Private Sub UserForm_Initialize()
  6.     Dim A As Range, S As String, E As Variant
  7.     Set Sh(1) = ThisWorkbook.Sheets("Database") '工作表如有變動時在此修改即可
  8.     Set Sh(2) = ThisWorkbook.Sheets.Add
  9.     AR_Image = Array(Image1, Image2, Image3, Image4)
  10.     AR_TexTbox = Array(TextBox1, TextBox2, TextBox3, TextBox4)
  11.     AR_Label = Array(Label1, Label4, Label6, Label8)
  12.     xTempPicture = "D:\NoPicture.jpg"
  13.     xName = "D:\temp.jpg"
  14.     照片Export Sh(1).Range("F2"), xTempPicture '置入"沒有圖片"檔 當作預設圖片及沒有圖片
  15.     ComboBox設定 ComboBox1, D
  16.     For E = 0 To UBound(AR_Image)
  17.         With AR_Image(E)            '設定圖片的顯示設模式 '***** 請自行調整******
  18.             .Picture = LoadPicture(xTempPicture)
  19.             .PictureAlignment = fmPictureAlignmentCenter ' ***  0,1,2,3,4
  20.             .PictureSizeMode = 3 'fmPictureSizeModeClip  ' ***  0,1,3
  21.         End With
  22.         AR_TexTbox(E).MultiLine = True   '指定控制項是否接受並顯示多行文字。
  23.         AR_Label(E).WordWrap = False   '內容在行末是否自動換行
  24.     Next
  25. End Sub
  26. '***********************************************************************************
  27. '以下為開啟UserForm1時會自動開啟1工作表,以下程式在關閉UserForm1時會自動關閉工作表
  28. Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
  29.     Application.DisplayAlerts = False
  30.     Sh(2).Delete
  31.     Kill xTempPicture
  32.     Kill xName ' "D:\temp.jpg"
  33.     Application.DisplayAlerts = True
  34. End Sub
  35. '***********************************************************************************
  36. Private Sub ComboBox1_Change()
  37.     Dim A As Variant, i As Integer, S As String, ii As Integer
  38.     清圖
  39.     With ComboBox1
  40.         If .ListIndex = -1 Then ComboBox2.Clear: ComboBox3.Clear: ComboBox4.Clear: Exit Sub
  41.         If IsArray(D(.Value)) Then A = D(.Value)(0) Else A = D(.Value)
  42.         ComboBox頁設定 ComboBox3, A
  43.         ComboBox設定 ComboBox2, D1
  44.         If ComboBox3.Enabled Then ComboBox3.ListIndex = 0
  45.     End With
  46. End Sub
  47. Private Sub ComboBox2_Change()
  48.     Dim A As Variant
  49.     With ComboBox2
  50.         清圖
  51.         If .ListIndex = -1 Then Exit Sub
  52.         A = D1(.Value)
  53.         If IsArray(D1(.Value)) Then A = D1(.Value)(0) Else A = D1(.Value)
  54.         ComboBox頁設定 ComboBox4, A
  55.         If ComboBox4.Enabled Then ComboBox4.ListIndex = 0
  56.     End With
  57. End Sub
  58. Private Sub ComboBox3_Change()
  59.     清圖
  60.     ComboBox4.Clear
  61.     If ComboBox3.ListIndex > -1 Then 設圖 ComboBox1, ComboBox3, D
  62. End Sub
  63. Private Sub ComboBox4_Change()
  64.     清圖
  65.     If ComboBox4.ListIndex > -1 Then 設圖 ComboBox2, ComboBox4, D1
  66.         
  67. End Sub
  68. Private Sub 清圖()
  69.     Dim i As Integer
  70.     For i = 0 To UBound(AR_Label)
  71.         AR_Label(i).Caption = "沒有此圖片"
  72.         AR_TexTbox(i).Text = ""
  73.         AR_Image(i).Picture = LoadPicture(xTempPicture) '表單預設的圖片 為 Databasse 工作表中的 F3 儲存格圖片
  74.     Next
  75. End Sub
  76. Private Sub 設圖(ComBo As MSForms.ComBobox, ComBobox As MSForms.ComBobox, D As Object)
  77.     Dim P As Object, i As Integer, ii As Integer
  78.     With ComBobox
  79.         For i = .ListIndex * 4 To (.ListIndex + 1) * 4 - 1
  80.             If i <= UBound(D(ComBo.Value)(0)) Then
  81.                 AR_Label(ii).Caption = D(ComBo.Value)(1)(i)
  82.                 AR_TexTbox(ii).Text = D(ComBo.Value)(2)(i)
  83.                 Set P = D(ComBo.Value)(0)(i)
  84.                 照片Export P, xName
  85.                 AR_Image(ii).Picture = LoadPicture(xName) '表單顯示圖片
  86.                 ii = ii + 1
  87.             End If
  88.         Next
  89.     End With
  90. End Sub
  91. Private Sub ComboBox頁設定(ComBo As MSForms.ComBobox, S As Variant)
  92.     Dim i As Integer
  93.     With ComBo
  94.         .Clear
  95.         Debug.Print .Name
  96.         ComBo.Enabled = IsArray(S)
  97.         If Not IsArray(S) Then Exit Sub
  98.         For i = 0 To UBound(S) Step 4
  99.             .AddItem Int((i + 1) / 4) + IIf(4 Mod (i + 1) >= 0, 1, 0)
  100.         Next
  101.     End With
  102. End Sub
  103. Private Sub ComboBox設定(ComBo As MSForms.ComBobox, D As Variant)
  104.     Dim A As Range, S As String, E As Variant, i As Integer, ii As Integer, iii As Integer, AR, AR1()
  105.     Dim xShape As Shape
  106.     Set D = CreateObject("Scripting.Dictionary")
  107.     For Each A In Sh(1).Range(Sh(1).Range("E3"), Sh(1).Range("E3").End(xlDown))
  108.         If ComBo.Name = "ComboBox1" Then
  109.             S = Replace(Trim(A), vbLf, Space(1))
  110.         Else
  111.             If ComboBox1 <> Replace(Trim(A), vbLf, Space(1)) Or Trim(A.Offset(, 5)) = "" Then GoTo Net
  112.             S = Replace(Trim(A.Offset(, 5)), vbLf, Space(1)) '換行字元 改成 Space(1)
  113.         End If
  114.         Set xShape = 圖片檢查(A.Offset(, 1).Address)
  115.         If Not xShape Is Nothing Then
  116.             If D.EXISTS(S) Then
  117.                 If IsArray(D(S)) Then
  118.                     AR = D(S)
  119.                     iii = UBound(AR(0)) + 1
  120.                     For ii = 0 To UBound(AR)
  121.                         ReDim AR1(0 To iii)
  122.                         For i = 0 To UBound(AR1)
  123.                             If ii = 0 Then If i < UBound(AR1) Then Set AR1(i) = AR(ii)(i) Else Set AR1(i) = xShape
  124.                             If ii = 1 Then If i < UBound(AR1) Then AR1(i) = AR(ii)(i) Else AR1(i) = A.Text
  125.                             If ii = 2 Then If i < UBound(AR1) Then AR1(i) = AR(ii)(i) Else AR1(i) = Sh(1).Cells(A.Row, "B").Text
  126.                         Next
  127.                         AR(ii) = AR1
  128.                     Next
  129.                     D(S) = AR
  130.                 Else
  131.                     D(S) = Array(Array(xShape), Array(A.Text), Array(Sh(1).Cells(A.Row, "B").Text))
  132.                 End If
  133.             Else
  134.                 D(S) = Array(Array(xShape), Array(A.Text), Array(Sh(1).Cells(A.Row, "B").Text))
  135.             End If
  136.         Else
  137.             If Not D.EXISTS(S) Then D(S) = False
  138.         End If
  139. Net:
  140.     Next
  141.     ComBo.Clear
  142.     If D.Count > 0 Then ComBo.List = D.KEYS
  143. End Sub
  144. Private Function 圖片檢查(xPicture As String) As Object
  145.     Dim S As Shape
  146.      Set 圖片檢查 = Nothing
  147.     For Each S In Sh(1).Shapes
  148.         '*************************************************
  149.         'Shape物件是照片且位置是D(ComboBox1.Value).Address)
  150.         If S.Type = msoPicture And S.TopLeftCell.Address = xPicture Then
  151.             Set 圖片檢查 = S
  152.             Exit For
  153.         End If
  154.         '***************************************************
  155.     Next
  156. End Function
  157. Private Sub 照片Export(P As Object, xName As String)
  158.     If xName <> "D:\temp.jpg" Then
  159.         P.CopyPicture
  160.     Else
  161.         P.Copy
  162.     End If
  163.     With Sh(2).ChartObjects.Add(1, 1, P.Width, P.Height) '新增圖表
  164.         .Chart.Paste '貼上圖片
  165.         .Chart.Export xName '匯出圖表,暫存圖片
  166.         .Delete '刪除圖表
  167.      End With
  168. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 23# GBKEE


    G大 版大您好:我有試用過新功能了,都可以使用解決了我的問題,真的很感謝您的大力幫忙,我再研究您的程式,
不過如果有新的想法需求,可能還要麻煩您了,再次感謝,我趕快再來研究看看。.....^^......

TOP

        靜思自在 : 天上最美是星星,人生最美是溫情。
返回列表 上一主題