Note: The other languages of the website are Google-translated. Back to English

Kako kopirati sliko z delovnega lista v uporabniški obrazec v Excelu?

V tem članku so prikazane metode kopiranja slike iz aktivnega delovnega lista v uporabniški obrazec v Excelu.

Kopirajte sliko z delovnega lista v Userform s kopiranjem in lepljenjem
Kopirajte sliko z delovnega lista v uporabniški obrazec s kodo VBA

Kopirajte sliko z delovnega lista v Userform s kopiranjem in lepljenjem

Naredite naslednje, če želite sliko kopirati iz delovnega lista v Userform.

1. Shift na delovni list vsebuje sliko, ki jo morate kopirati v Userform, in nato pritisnite druga + F11 tipke, da odprete Microsoft Visual Basic za aplikacije okno.

2. V Ljubljani Microsoft Visual Basic za aplikacije okno, kliknite Vstavi > Uporabniška oblika. Oglejte si posnetek zaslona:

3. Zdaj vstavite Image Control v UserForm. Kliknite Image gumb v Toolbox v pogovorno okno, nato v Uporabniški obrazec ročno. Oglejte si posnetek zaslona:

4. Z desno miškino tipko kliknite vstavljeni nadzor slike in kliknite Nepremičnine iz kontekstnega menija, kot je prikazano spodaj:

5. Potem lahko vidite a Nepremičnine podokno se prikaže na levi strani Microsoft Visual Basic za aplikacije okno.

6. Vrnite se na delovni list in izberite sliko, ki jo želite prikazati v uporabniškem obrazcu, nato pa s pritiskom na sliko kopirajte Ctrl + C ključi.

7. Pojdi v Microsoft Visual Basic za aplikacije spet se pomaknite navzdol, da kliknete Slika in nato prilepite kopirano ime slike vanjo pod zavihek Abeceda.

Zdaj je slika na delovnem listu kopirana v uporabniški obrazec.

Kopirajte sliko z delovnega lista v uporabniški obrazec s kodo VBA

Ta razdelek vam bo pokazal rešitev za kopiranje več slik z delovnega lista v uporabniški obrazec in nato prikazal ustrezno sliko v uporabniškem obrazcu, tako da izberete ime slike iz kombiniranega polja. Naredite naslednje.

1. Sledite zgornjim korakom 1 in 2, da v svoj delovni list vstavite uporabniški obrazec.

2. Nato vstavite a Nadzor okvirja v UserFrom, kot je prikazano spodaj:

3. Z desno miškino tipko kliknite vstavljeni okvir in izberite Nepremičnine iz kontekstnega menija. Na levi Nepremičnine podokno, izberite False Iz vidno polje. Oglejte si posnetek zaslona:

4. Vstavite nadzor več slik v okvir, kot je prikazano spodaj.

5. Vrnite se na delovni list in izberite sliko, ki jo želite prikazati v Userform, in pritisnite na Ctrl + C tipke za kopiranje.

6. Pojdi v Microsoft Visual Basic za aplikacije okno, z desno miškino tipko kliknite prvi Image control in izberite Nepremičnine v meniju z desnim klikom. Oglejte si prikazan posnetek zaslona.

7. V Ljubljani Nepremičnine kliknite podokno Slika polje, nato pritisnite Ctrl + V tipke, da prilepite sliko, ki ste jo kopirali v koraku 5, in nato izberite 1 - fmPictureSizeModeStrtch Iz PictureSizeMode spustni seznam, kot je prikazano na sliki spodaj.

8. Ponovite korak 5 - 7, da prilepite druge slike z delovnega lista na levi nadzor slike v UserForm. In rezultat se bo prikazal, kot je prikazano spodaj.

9. Premakni Okvirji nadzor v kot UserForm, nato vstavite novega Image nadzor in a Kombinirana škatla nadzor v UserForm. Oglejte si posnetek zaslona:

10. Z desno miškino tipko kliknite Uporabniški obrazecIn nato Ogled kode. Nato kopirajte in prilepite spodnjo kodo VBA, da zamenjate prvotno v okno Code.

Koda VBA1: kopirajte sliko z delovnega lista v uporabniški obrazec

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
End Sub

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()
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:

The Best Office Productivity Tools

Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office / Excel 2007-2021 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.
kte tab 201905

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!
officetab bottom
Comments (1)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
I'm having difficulties, can someone explain the code for me?
There are no comments posted here yet
Leave your comments
Posting as Guest
Rate this post:
0   Characters
Suggested Locations

Follow Us

Copyright © 2009 - | All rights reserved. Powered by ExtendOffice. | Sitemap
Microsoft and the Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.
Protected by Sectigo SSL