ไปยังเนื้อหาหลัก

วิธีแปลง URL ของรูปภาพเป็นรูปภาพจริงใน Excel

doc url ถึง img 1

หากคุณมีรายการที่อยู่ URL รูปภาพในคอลัมน์ A และตอนนี้คุณต้องการดาวน์โหลดรูปภาพที่เกี่ยวข้องจาก URL และแสดงลงในคอลัมน์ B ที่อยู่ติดกันตามภาพหน้าจอด้านซ้ายที่แสดง ใน Excel คุณจะดึงรูปภาพจริงจาก URL ของรูปภาพอย่างรวดเร็วและง่ายดายได้อย่างไร

แปลง URL ของรูปภาพเป็นรูปภาพจริงด้วยรหัส VBA

แปลง URL ของรูปภาพเป็นรูปภาพจริงด้วย Kutools for Excel


แปลง URL ของรูปภาพเป็นรูปภาพจริงด้วยรหัส VBA

รหัส VBA ต่อไปนี้สามารถช่วยให้คุณดึงภาพจริงจากที่อยู่ URL ของรูปภาพได้อย่างรวดเร็วโปรดดำเนินการดังนี้:

1. กด ALT + F11 ปุ่มเพื่อเปิดหน้าต่าง Microsoft Visual Basic for Applications

2. คลิก สิ่งที่ใส่เข้าไป > โมดูลและวางรหัสต่อไปนี้ในหน้าต่างโมดูล

รหัส VBA: แปลง URL ของภาพเป็นภาพจริง:

Sub URLPictureInsert()
Dim Pshp As Shape
Dim xRg As Range
Dim xCol As Long
On Error Resume Next
Application.ScreenUpdating = False
Set Rng = ActiveSheet.Range("A2:A5")
For Each cell In Rng
filenam = cell
ActiveSheet.Pictures.Insert(filenam).Select
Set Pshp = Selection.ShapeRange.Item(1)
If Pshp Is Nothing Then GoTo lab
xCol = cell.Column + 1
Set xRg = Cells(cell.Row, xCol)
With Pshp
.LockAspectRatio = msoFalse
If .Width > xRg.Width Then .Width = xRg.Width * 2 / 3
If .Height > xRg.Height Then .Height = xRg.Height * 2 / 3
.Top = xRg.Top + (xRg.Height - .Height) / 2
.Left = xRg.Left + (xRg.Width - .Width) / 2
End With
lab:
Set Pshp = Nothing
Range("A2").Select
Next
Application.ScreenUpdating = True
End Sub

หมายเหตุ: 

  • 1. ในโค้ดด้านบน A2: A5 คือช่วงของเซลล์ที่มีที่อยู่ URL ที่คุณต้องการแยกรูปภาพคุณควรเปลี่ยนการอ้างอิงเซลล์ตามความต้องการของคุณ
  • 2. ด้วยรหัสนี้คุณไม่สามารถระบุขนาดของภาพที่แยกออกมาได้ตามที่คุณต้องการ
  • 3. โค้ดด้านบนสามารถดึงเฉพาะรูปภาพที่แสดงไว้ในเซลล์นอกเหนือจากคอลัมน์ URL ของคุณคุณไม่สามารถระบุเซลล์ที่จะส่งออกรูปภาพได้
  • 4. คุณควรมีความรู้พื้นฐานเกี่ยวกับรหัสหากอักขระใดพลาดหรือไม่ถูกต้องรหัสจะไม่สามารถดำเนินการได้สำเร็จ

3. จากนั้นกด F5 กุญแจสำคัญในการเรียกใช้รหัสนี้และรูปภาพที่เกี่ยวข้องทั้งหมดจะถูกดึงออกจาก URL ของรูปภาพไปยังคอลัมน์ที่อยู่ติดกันพร้อมกันและรูปภาพจะถูกวางไว้ที่กึ่งกลางของเซลล์เฉพาะของคุณดูภาพหน้าจอ:

doc url ถึง img 2


แปลง URL ของรูปภาพเป็นรูปภาพจริงด้วย Kutools for Excel

หากคุณไม่คุ้นเคยกับรหัส VBA หรือต้องการแก้ไขข้อ จำกัด ของรหัสข้างต้น Kutools สำหรับ Excel's แทรกเส้นทางฟอร์มรูปภาพ (URL) คุณลักษณะนี้สามารถช่วยให้คุณแทรกรูปภาพที่สอดคล้องกันได้อย่างรวดเร็วตามที่อยู่ URL หรือเส้นทางเฉพาะในคอมพิวเตอร์ของคุณ คลิกเพื่อดาวน์โหลด Kutools for Excel!

หมายเหตุ:ที่จะใช้สิ่งนี้ แทรกเส้นทางฟอร์มรูปภาพ (URL)ประการแรกคุณควรดาวน์โหลดไฟล์ Kutools สำหรับ Excelแล้วใช้คุณสมบัตินี้อย่างรวดเร็วและง่ายดาย

หลังจากการติดตั้ง Kutools สำหรับ Excelโปรดทำตามนี้:

1. คลิก Kutools > สิ่งที่ใส่เข้าไป > แทรกเส้นทางฟอร์มรูปภาพ (URL)ในกล่องโต้ตอบที่โผล่ออกมาโปรดตั้งค่าการดำเนินการต่อไปนี้ดูภาพหน้าจอ:

doc url ถึง img 3 doc url ถึง img 4

2. จากนั้นคลิก Ok และรูปภาพจะถูกดึงออกมาจาก URL ดูภาพหน้าจอ:

doc url ถึง img 1

คลิกเพื่อดาวน์โหลดและทดลองใช้ Kutools for Excel ฟรีทันที!

สุดยอดเครื่องมือเพิ่มผลผลิตในสำนักงาน

🤖 Kutools AI ผู้ช่วย: ปฏิวัติการวิเคราะห์ข้อมูลโดยยึดตาม: การดำเนินการที่ชาญฉลาด   |  สร้างรหัส  |  สร้างสูตรที่กำหนดเอง  |  วิเคราะห์ข้อมูลและสร้างแผนภูมิ  |  เรียกใช้ฟังก์ชัน Kutools...
คุณสมบัติยอดนิยม: ค้นหา เน้น หรือระบุรายการที่ซ้ำกัน   |  ลบแถวว่าง   |  รวมคอลัมน์หรือเซลล์โดยไม่สูญเสียข้อมูล   |   รอบโดยไม่มีสูตร ...
การค้นหาขั้นสูง: VLookup หลายเกณฑ์    VLookup หลายค่า  |   VLookup ข้ามหลายแผ่น   |   การค้นหาที่ไม่ชัดเจน ....
รายการแบบเลื่อนลงขั้นสูง: สร้างรายการแบบหล่นลงอย่างรวดเร็ว   |  รายการแบบหล่นลงขึ้นอยู่กับ   |  เลือกหลายรายการแบบหล่นลง ....
ผู้จัดการคอลัมน์: เพิ่มจำนวนคอลัมน์เฉพาะ  |  ย้ายคอลัมน์  |  สลับสถานะการมองเห็นของคอลัมน์ที่ซ่อนอยู่  |  เปรียบเทียบช่วงและคอลัมน์ ...
คุณสมบัติเด่น: กริดโฟกัส   |  มุมมองการออกแบบ   |   บาร์สูตรใหญ่    สมุดงานและตัวจัดการชีต   |  ห้องสมุดทรัพยากร (ข้อความอัตโนมัติ)   |  เลือกวันที่   |  รวมแผ่นงาน   |  เข้ารหัส/ถอดรหัสเซลล์    ส่งอีเมลตามรายการ   |  ซุปเปอร์ฟิลเตอร์   |   ตัวกรองพิเศษ (กรองตัวหนา/ตัวเอียง/ขีดทับ...) ...
ชุดเครื่องมือ 15 อันดับแรก12 ข้อความ เครื่องมือ (เพิ่มข้อความ, ลบอักขระ, ... )   |   50 + แผนภูมิ ประเภท (แผนภูมิ Gantt, ... )   |   40+ ใช้งานได้จริง สูตร (คำนวณอายุตามวันเกิด, ... )   |   19 การแทรก เครื่องมือ (ใส่ QR Code, แทรกรูปภาพจากเส้นทาง, ... )   |   12 การแปลง เครื่องมือ (ตัวเลขเป็นคำ, การแปลงสกุลเงิน, ... )   |   7 ผสานและแยก เครื่องมือ (แถวรวมขั้นสูง, แยกเซลล์, ... )   |   ... และอื่น ๆ

เพิ่มพูนทักษะ Excel ของคุณด้วย Kutools สำหรับ Excel และสัมผัสประสิทธิภาพอย่างที่ไม่เคยมีมาก่อน Kutools สำหรับ Excel เสนอคุณสมบัติขั้นสูงมากกว่า 300 รายการเพื่อเพิ่มประสิทธิภาพและประหยัดเวลา  คลิกที่นี่เพื่อรับคุณสมบัติที่คุณต้องการมากที่สุด...

รายละเอียด


แท็บ Office นำอินเทอร์เฟซแบบแท็บมาที่ Office และทำให้งานของคุณง่ายขึ้นมาก

  • เปิดใช้งานการแก้ไขและอ่านแบบแท็บใน Word, Excel, PowerPoint, ผู้จัดพิมพ์, Access, Visio และโครงการ
  • เปิดและสร้างเอกสารหลายรายการในแท็บใหม่ของหน้าต่างเดียวกันแทนที่จะเป็นในหน้าต่างใหม่
  • เพิ่มประสิทธิภาพการทำงานของคุณ 50% และลดการคลิกเมาส์หลายร้อยครั้งให้คุณทุกวัน!
Comments (61)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
can anyone help to extract mutiple links folllowed by comma  in one cell 
This comment was minimized by the moderator on the site
I own Kutools and I cannot seem to get this function to work properly. After I run it based on the examples above I get a message that says "1 picture(s) failed to be inserted"
Its not an htpps address. And the link the works fine when clicking from excel.
Please help
This comment was minimized by the moderator on the site
I have the same problem now. It worked very well yesterday, but today it's just not working :(
This comment was minimized by the moderator on the site
If I want the image to resize with the cell, is it as simple as changing this line to "msoTrue"?.LockAspectRatio = msoFalse


This comment was minimized by the moderator on the site
When I renew it takes the same picture again
So it adds images on top of each other
how can i prevent this?
Do not add the added picture again ?how can I do?
edit: also pictures are not loading when we open later?
This comment was minimized by the moderator on the site
When I renew it takes the same picture againSo it adds images on top of each other
how can i prevent this?
Do not add the added picture again ?how can I do?
This comment was minimized by the moderator on the site
thank you for VBA code, i able to get the url images as picture
but, after file closed, and then i opened it again, picture missing.
how to solve this problem?
This comment was minimized by the moderator on the site
Hello, Robby,After copying and pasting the code, when you close the workbook, you should save the file as Excel Macro-Enabled Workbook format for saving the code.When reopen the workbook, you should click the Enable Content button from the yellow ribbon at the top of the workbook.Please try, thank you!
This comment was minimized by the moderator on the site
thank you for fast response
I have save as Excel Enable Workbook and also Enable Content, and Picture will be shown up if i connected to internet, but when offline mode, the picture will be missing, Excel message : Picture can't be display
is there any solution so the picture will still shown up even though i am in offline mode (no internet available)
This comment was minimized by the moderator on the site
Hi, Robby, In this case, if you are in offline mode, I recommend you to use the Insert Pictures form Path(URL) feature of Kutools for Excel, you can download the Kutools and use it 30 days for free trail. After inserting the pictures, the pictures will be saved into the workbook.Please try.
This comment was minimized by the moderator on the site
What image types does this work with? I have mostly svg files and those are not working, but png and jpeg are fine.
This comment was minimized by the moderator on the site
Hello, travwoody,Yes, as you said, the code does not work for the svg files.Or can you insert a picture url here? We can test your image url for modifying the code.Thank you!
This comment was minimized by the moderator on the site
Why this line is not working for me?
Set Pshp = Selection.ShapeRange.Item(1)
Pshp object is becoming nothing, even though I have a valid image URL
This comment was minimized by the moderator on the site
I will also specify that I am writing about the VBA script
This comment was minimized by the moderator on the site
This code works great. Thank you!
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations