[英]Adding image to a worksheet from a userform (excel vba)
我有一个带有浏览按钮的用户窗体,该按钮允许用户搜索驱动器并选择图片(例如徽标):
Private Sub BrowseButton_Click()
Dim strFileName As String
'use GetOpenFilename Method to select picture
strFileName = Application.GetOpenFilename(filefilter:="Tiff Files(*.tif;*.tiff),*.tif;*.tiff,JPEG Files (*.jpg;*.jpeg;*.jfif;*.jpe),*.jpg;*.jpeg;*.jfif;*.jpe,Bitmap Files(*.bmp),*.bmp", FilterIndex:=2, Title:="Select a File", MultiSelect:=False)
If strFileName = "False" Then
MsgBox "File Not Selected!"
Else
'load picture to Image control, using LoadPicture property
Me.Image1.Picture = LoadPicture(strFileName)
'after any change vba has to be told to refresh the UserForm for the change to appear
Me.Repaint
'label caption changes after picture is loaded
Me.Label1.Caption = "Logo loaded"
End If
End Sub
所选图片存储在用户窗体的图像框中。 我有一个提交按钮,当选中该按钮时,我希望获得用户从图像框中选择的“图片”并将其插入到图纸上的特定位置。 这是我到目前为止的内容:
Sub Image9_Click()
'' Submit Button
Dim sld As Worksheet
Set sld = Sheets("Sliders")
Dim logo As Image
logo = colourForm.Image1
Call updateAllColScheme ''Ignore this
colourForm.Hide
End Sub
这根本不起作用,因为它会引发错误,有人知道这是否可以完成吗?
这很简单
只需添加一个TextBox(在用户窗体中是不可见的)
Private Sub BrowseButton_Click()
Dim strFileName As String
use GetOpenFilename Method to select picture
strFileName = Application.GetOpenFilename(filefilter:="Tiff Files(*.tif;*.tiff),*.tif;*.tiff,JPEG Files (*.jpg;*.jpeg;*.jfif;*.jpe),*.jpg;*.jpeg;*.jfif;*.jpe,Bitmap Files(*.bmp),*.bmp", FilterIndex:=2, Title:="Select a File", MultiSelect:=False)
TextBox1 = strFileName 'use to save URL or Link from picture
If strFileName = "False" Then
MsgBox "File Not Selected!"
Else
'load picture to Image control, using LoadPicture property
Me.Image1.Picture = LoadPicture(strFileName)
'after any change vba has to be told to refresh the UserForm for the change to appear
Me.Repaint
'label caption changes after picture is loaded
Me.Label1.Caption = "Logo loaded"
End If
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.