Execl automatically loads images under the Directory

Source: Internet
Author: User

During the project implementation process, employees were taken photos. However, it is difficult to insert a picture to the employee, and check whether the name is correct or not.

For comprehensive requirements, find relevant information on the Internet. Then summarize the information based on the actual situation. The solution is as follows:

1. Import personnel information

2. Enable the macro function of the execl table and add macros.

3. Deformation of macro code

The Code is as follows:

Sub autoaddpic ()
Application. screenupdating = false


For each SHP in activesheet. Shapes
If SHP. type = msopicture then SHP. Delete
Next
Dim mypcname as string, pictemp as picture
For I = 2 to thisworkbook. activesheet. usedrange. Rows. Count
'If (activesheet. cells (I, 1). value = "name") then

'Activesheet. Pictures (). delete' deletes the original image in the cell.

Mypcname = activesheet. cells (I, 1). Value & activesheet. cells (I, 3). Value & ". jpg"
Activesheet. cells (I, 6). Delete
Activesheet. cells (I, 6). Select
Dim myfile as object
Set myfile = Createobject ("scripting. FileSystemObject ")
'Insert Image
If myfile. fileexists (thisworkbook. Path & "\" & "personnel information" & "\" & mypcname) = true then
Set pictemp = activesheet. Pictures. insert (thisworkbook. Path & "\" & "personnel information" & "\" & mypcname)
'Pictemp. Name = K & K. row' sets the name of the inserted image.
Pictemp. Placement = xlmoveandsize 'sets the size and position of an image as the cell changes.
With pictemp. shaperange
. Lockaspectratio = msofalse 'cancel image Aspect Ratio lock
. Height = cells (I, 6). Height-1 'sets the height of the inserted image to be equal to the height of the cell.
. Width = cells (I, 6). Width-1 'sets the width of the inserted image to be equal to the width of the cell.
End

'Pictemp. Select

Set pictemp = nothing 'reset the image object

End if
'If myfile. fileexists (thisworkbook. Path & "\" & "personnel information" & "\" & mypcname) = false then
'Msgbox thisworkbook. Path & "\" & "111" & "\" & mypcname & "no image"
'Else
'Activesheet. Pictures. insert (thisworkbook. Path & "\" & "" & "\" & mypcname). Select
'End if
'End if

Next I
Application. screenupdating = true

End sub

 

Execl automatically loads directory slices

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.