具有来自主模块的用户窗体调用功能和填充图像框

have userform call function from main module and Populate imageBox

Public Function LoadImage() As Object

  For Each pics In sheetImages.Shapes
    If (CStr(pics.Name) = CStr(currpartImage)) Then
      Me.ImagePreview.Picture =PictureFromShape(sheetImages.Shapes(currImage))
      Me.ImagePreview.PictureSizeMode = 3
      currImageRow = sheetImages.Shapes(currpartImage).TopLeftCell.row + 1
    End If
  Next
End Function

我试图让一个用户窗体从我的主模块调用这个函数,并将图像框设置为形状...当这个函数在用户窗体代码中时它运行正常但我试图避免必须为我的所有用户表单复制此代码....当我将此功能放入用户表单时 - "Me." & "as Object" 被删除

向您的例程添加一个参数:

Public Sub LoadImage(imageControl as Object) As Object
  For Each pics In sheetImages.Shapes
    If (CStr(pics.Name) = CStr(currpartImage)) Then
      imageControl .Picture =PictureFromShape(sheetImages.Shapes(currImage))
      imageControl .PictureSizeMode = 3
      currImageRow = sheetImages.Shapes(currpartImage).TopLeftCell.row + 1
    End If
  Next
End Sub

从您的表单中调用:

LoadImage Me.ImagePreview

您还需要传递在 LoadImage 中引用但不在用户表单范围之外的任何其他项目。