Excel 导入URL为jpg,并调整图像的最大列宽和行高
我正在从网上下载大约8KJPG文件。文件的URL在B列中,我想在C列中输出实际的图像。我有一些代码,我把它们拼凑在一起下载了,但是图像很小。我要原码的。因此,我想确定最大的jpg文件是什么,并使行高和列宽与之匹配。以下是我目前掌握的代码:Excel 导入URL为jpg,并调整图像的最大列宽和行高,excel,vba,Excel,Vba,我正在从网上下载大约8KJPG文件。文件的URL在B列中,我想在C列中输出实际的图像。我有一些代码,我把它们拼凑在一起下载了,但是图像很小。我要原码的。因此,我想确定最大的jpg文件是什么,并使行高和列宽与之匹配。以下是我目前掌握的代码: Sub Test2() Dim Pic As Picture Dim SrcRange As Range Dim LastRowA As Long LastRowA = Cells.Find(What:="*", _
Sub Test2()
Dim Pic As Picture
Dim SrcRange As Range
Dim LastRowA As Long
LastRowA = Cells.Find(What:="*", _
After:=Range("A1"), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
Set SrcRange = ActiveSheet.Range(Cells(2, 1), Cells(LastRowA, 1))
SrcRange.Rows().RowHeight = ActiveSheet.Columns(3).Width * 2
For Each cell In SrcRange.Cells
With cell
Set Pic = .Parent.Pictures.Insert(.Value)
With .Offset(, 1)
Pic.Top = .Top
Pic.Left = .Left
Pic.Height = .Height
Pic.Width = .Width
Pic.Border.Color = vbRed
End With
End With
Next
End Sub
一如既往,我们将非常感谢您的帮助。我已经5年没有做过任何excel vba编码了。我有点生疏了。我正在运行excel 2016 将图片纵横比设置为false
Pic.ShapeRange.LockAspectRatio = msoFalse
在您的代码中
For Each cell In SrcRange.Cells
With cell
Set Pic = .Parent.Pictures.Insert(.Value)
Pic.ShapeRange.LockAspectRatio = msoFalse '<~~ set LockAspetRatio to false
With .Offset(, 1)
Pic.Top = .Top
Pic.Left = .Left
Pic.Height = .Height
Pic.Width = .Width
Pic.Border.Color = vbRed
End With
End With
Next
Sub Test2()
Dim Pic As Picture
Dim SrcRange As Range
Dim LastRowA As Long
Dim l As Single, t As Single, w As Single, h As Single
Dim cell As Range
LastRowA = Cells.Find(What:="*", _
After:=Range("A1"), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
Set SrcRange = ActiveSheet.Range(Cells(2, 1), Cells(LastRowA, 1))
SrcRange.Rows().RowHeight = ActiveSheet.Columns(3).Width * 2
For Each cell In SrcRange.Cells
With cell
t = .Top
l = .Left
w = .Width
h = .Height
Set shp = ActiveSheet.Shapes.AddPicture(.Value, msoCTrue, msoCTrue, l, t, w, h)
End With
Next
End Sub