我需要的图像嵌入到Excel中通过VBA,电子表格等,每当我重新安置我的excel文件,图像仍然会出现。我怎样才能做到这一点?图像嵌入到Excel电子表格 - VBA
回答
此代码将插入当前工作表,并将其放置在一个图像,以单元格E10:
Set oPic = Application.ActiveSheet.Shapes.AddPicture("d:\temp\mypic.jpg", False, True, 1, 1, 1, 1)
oPic.ScaleHeight 1, True
oPic.ScaleWidth 1, True
oPic.Top = Range("E10").Top
oPic.Left = Range("E10").Left
你尝试使用宏录制?
这是它产生的对我来说:使用谷歌的搜索字词
Sub Macro1()
ActiveSheet.Pictures.Insert ("C:\mypicture.jpg")
End Sub
此外吨的信息:“插入图片使用VBA Excel中”。以下代码取自ExcelTip全部感谢原作者Erlandsen Data Consulting。
有了下面你可以在一个工作表中的任何范围内插入图片和图片本身仍然在原来的位置,他们将只要保持宏。
图片可以居中水平和/或垂直。
Sub TestInsertPicture()
InsertPicture "C:\FolderName\PictureFileName.gif", _
Range("D10"), True, True
End Sub
Sub InsertPicture(PictureFileName As String, TargetCell As Range, _
CenterH As Boolean, CenterV As Boolean)
' inserts a picture at the top left position of TargetCell
' the picture can be centered horizontally and/or vertically
Dim p As Object, t As Double, l As Double, w As Double, h As Double
If TypeName(ActiveSheet) <> "Worksheet" Then Exit Sub
If Dir(PictureFileName) = "" Then Exit Sub
' import picture
Set p = ActiveSheet.Pictures.Insert(PictureFileName)
' determine positions
With TargetCell
t = .Top
l = .Left
If CenterH Then
w = .Offset(0, 1).Left - .Left
l = l + w/2 - p.Width/2
If l < 1 Then l = 1
End If
If CenterV Then
h = .Offset(1, 0).Top - .Top
t = t + h/2 - p.Height/2
If t < 1 Then t = 1
End If
End With
' position picture
With p
.Top = t
.Left = l
End With
Set p = Nothing
End Sub
使用下面的宏,您可以插入图片并将它们放入工作表中的任何范围。
Sub TestInsertPictureInRange()
InsertPictureInRange "C:\FolderName\PictureFileName.gif", _
Range("B5:D10")
End Sub
Sub InsertPictureInRange(PictureFileName As String, TargetCells As Range)
' inserts a picture and resizes it to fit the TargetCells range
Dim p As Object, t As Double, l As Double, w As Double, h As Double
If TypeName(ActiveSheet) <> "Worksheet" Then Exit Sub
If Dir(PictureFileName) = "" Then Exit Sub
' import picture
Set p = ActiveSheet.Pictures.Insert(PictureFileName)
' determine positions
With TargetCells
t = .Top
l = .Left
w = .Offset(0, .Columns.Count).Left - .Left
h = .Offset(.Rows.Count, 0).Top - .Top
End With
' position picture
With p
.Top = t
.Left = l
.Width = w
.Height = h
End With
Set p = Nothing
End Sub
我们只是使用了相同的解决方案,但是一旦外部图像被移动或删除,它就不起作用。 – danielpiestrak
那么为什么不问我而不是投票!我会很乐意帮助你进一步的代码... – Reafidy
哦,我downvoted,因为OP提到,图片无法链接,所以Excel文件可以移动,所以我认为这是一个不好的答案这个特定的问题。 对不起,没有冒犯的意思〜我只参加了这个网站活跃约一个星期了。也许下次我只会投票。 – danielpiestrak
- 1. Excel xml电子表格 - 是否可以嵌入图像?
- 2. 从VBA表格插入复选框值到Excel电子表格
- 3. 将图像插入到Excel电子表格中
- 4. Excel VBA将单个图像嵌入电子邮件联系人列表
- 5. VBA插入值到电子表格
- 6. VBA导入Excel电子表格到Access行由行
- 7. 如何使用嵌入图生成Excel电子表格?
- 8. 将Excel电子表格导入到phpMyAdmin
- 9. 嵌入式图像从Excel VBA
- 10. 将PDF嵌入到电子表格中
- 11. 将excel电子表格合并到一个电子表格中
- 12. 使用VBA将表单值插入Excel电子表格
- 13. 将VBA表格中的无线电值插入Excel电子表格
- 14. 将数据从访问导入到打开的Excel电子表格中? (Excel VBA)
- 15. LINQ表格到Excel电子表格
- 16. 将自定义雷达图表嵌入到电子表格中
- 17. Word VBA刷新嵌入式Excel图表
- 18. Excel VBA到电子邮件
- 19. 使用VBA将Access文件表导出到Excel电子表格
- 20. 将Excel电子表格数据导入包含VBA的另一个Excel电子表格
- 21. 传输图像路径从Excel电子表格到HTML文件
- 22. VBA在.doc文件中插入Excel complexe电子表格
- 23. 使用VBA将网页导入Excel电子表格
- 24. 不从电子表格的开头写入。 Excel VBA。
- 25. VBA访问 - >自动导入Excel电子表格与HYPERLINKS
- 26. ACCPAC和Excel电子表格
- 27. Excel VBA脚本/宏到谷歌电子表格脚本/宏
- 28. 将表格从Outlook电子邮件复制到Excel文件 - VBA
- 29. VBA将Excel电子表格链接到Access
- 30. VBA Excel - 将列名保存到MS Access的电子表格中
谢谢,你只是我指出了正确的方向! – danielpiestrak