如何在Excel中将图像从工作表复制到用户窗体?

网友投稿 294 2023-12-19

如何在Excel中将图像从工作表复制到用户窗体?

本文将向您展示将图像从活动工作表复制到Excel中的用户窗体的方法。

通过复制和粘贴将图像从工作表复制到用户窗体 使用VBA代码将图像从工作表复制到用户窗体

通过复制和粘贴将图像从工作表复制到用户窗体
惊人的! 在 Excel 中使用高效的选项卡,如 Chrome、Firefox 和 Safari! 每天节省50%的时间,并减少数千次鼠标单击!

请执行以下操作,将图像从工作表复制到用户窗体。

1.切换到工作表,其中包含您需要复制到用户窗体的图像,然后按 其他 + F11 钥匙一起打开 Microsoft Visual Basic应用程序 窗口。

2.在 Microsoft Visual Basic应用程序 窗口,请点击 插页 > 用户表格。 看截图:

3.现在,请在用户窗体中插入一个图像控件。 请点击 图片 按钮在 工具箱 对话框,然后将图像控件绘制到 用户表格 手动。 看截图:

4.右键单击插入的Image控件,然后单击“确定”。 租房 从上下文菜单中,如下所示的屏幕截图:

5.然后您可以看到一个 租房 窗格显示在 Microsoft Visual Basic应用程序 窗口。

如何在Excel中将图像从工作表复制到用户窗体?

6.返回工作表,然后选择要在用户窗体中显示的图片,然后按来复制图片 按Ctrl + C 键。

7.进入 Microsoft Visual Basic应用程序 再次向下滚动以单击 图片 字段,然后将复制的图片名称粘贴到“字母”选项卡下。

现在,工作表中的图片已复制到用户窗体中。

使用VBA代码将图像从工作表复制到用户窗体

本节将向您显示一种解决方法,将多张图片从工作表复制到一个用户窗体,然后通过从“组合”框中选择图片名称,在用户窗体中显示相应的图片。 请执行以下操作。

1.请按照上述步骤1和2进行操作,或者在工作表中插入一个用户表单

2.然后插入一个 框架控制 进入UserFrom,如下图所示:

3.右键单击插入的框架,然后选择 租房 从上下文菜单中。 在左边 租房 面板,请选择 来自 可见 领域。 看截图:

4.如下图所示,将多个Image控件插入Frame中。

5.返回工作表并选择要在用户窗体中显示的图片,然后按 按Ctrl + C 键复制它。

6.进入 Microsoft Visual Basic应用程序 窗口,右键单击第一个图像控件,然后选择 租房 从右键单击菜单中。 请参阅显示的屏幕截图。

7.在 租房 窗格,请单击 图片 字段,然后按 按Ctrl + V 键粘贴您在步骤5中复制的图片,然后选择 1 – fmPictureSizeModeStrtch 来自 图片大小模式 下拉列表如下图所示。

8.重复步骤5-7,将其他图片从工作表粘贴到用户窗体的左侧“图像”控件中。 结果将显示如下所示的屏幕截图。

9.移动 控件移到用户窗体的角,然后插入一个新的 图片 控制和 组合框 控制进入UserForm。 看截图:

10.右键单击 用户表格,然后单击 查看代码。 然后复制并粘贴下面的VBA代码,以将原始代码替换到“代码”窗口中。

VBA代码1:将图像从工作表复制到用户窗体

Private Sub ComboBox1_Change() UserForm1.Controls.Item("Image4").Picture = UserForm1.Controls.Item(UserForm1.ComboBox1.Value).Picture End Sub Private Sub UserForm_Initialize() Dim xImg As Control On Error Resume Next For Each xImg In UserForm1.Controls If TypeName(xImg) = "Image" And xImg.Name <> "Image4" Then UserForm1.ComboBox1.AddItem xImg.Name End If Next End Sub
Copy
Note: In the code, UserForm1 is the name of the inserted UserForm, Image4 is the name of the Image control you will display pictures inside. And Image represents all Image controls which contain the pictures you copied from the worksheet. ComboBox1 is the combobox name you have inserted into the userform. Please change them to your own. 11. Close the Microsoft Visual Basic for Applications window. 12. Insert a Command button into the worksheet by clicking Developer > Insert > Command Button (ActiveX Control). 13. Right-click the command button and select View Code from the Context menu. And then copy and paste the below VBA code into the Code window. And finally close the window. VBA code2: Copy image from worksheet to Userform Private Sub CommandButton1_Click() UserForm1.Show End Sub 15. Click Developer > Design Mode to turn off the Design Mode. From now on, when clicking the command button, the UserForm will pop up. You can display picture by selecting the image name from the combo box. See screenshot: Select different names from the combo box will display different pictures in the UserForm. Related Articles: How to center a picture in an Excel cell? How to check if a cell contains picture in Excel? How to insert image or picture dynamically in cell based on cell value in Excel? How to enlarge image when click on it in Excel? Best Office Productivity Tools Transform Hours into Minutes with Kutools for Excel! Ready to supercharge your Excel tasks? Harness the power of Kutools for Excel - your ultimate time-saving tool. Streamline intricate tasks and glide through your data like a pro. Experience Excel at lightning speed! Why You Need Kutools for Excel 🛠️ Over 300 Powerful Features: Kutools is packed with more than 300 advanced features, simplifying your work in over 1500 scenarios. 📈 Superior Data Processing: Merge cells, remove duplicates, and perform advanced data conversions – all without breaking a sweat! ⏱️ Efficient Batch Operations: Why put in extra effort when you can work smart? Import, export, combine, and tweak data in bulk with ease. 📊 Customizable Charts and Reports: Access a broad variety of additional charts and generate insightful reports that tell a story. 🗄️ Powerful Navigation Pane: Gain an advantage with the robust Column Manager, Worksheet Manager, and Custom Favorites. 📝 Seven Types of Drop-down Lists: Make data entry a breeze with drop-down lists of various features and types. 🎓 User-Friendly: A breeze for beginners and a powerful tool for experts. Download Now and Soar Through Time with Excel! Read More... Free Download... Purchase... Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project. Open and create multiple documents in new tabs of the same window, rather than in new windows. Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day! Read More... Free Download... Purchase...

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:如何在Excel中仅将超链接从一个单元复制到另一个单元?
下一篇:如何在Excel中复制多个选择或范围?
相关文章