excel - Excel VBA change shape fill to an image in a loop
问题描述
I have created a workbook for printing reports from a central dataset. The data is loaded using an index match formula which my VBA iterates through and adds 1 to the reference to get to the next set of data.
The only issue I’m having is that my images aren’t getting updated.
cur_val = to the starting reference number
props_cnt = to the last reference number image_path = the link to an image which is generated by an index match formula which updates as the reference number is changed
map_path = the link to a map (image) which is generated by an index match formula which updates as the reference number is changed
export_report_as_pdf = simple function to print to pdf
Any ideas why the image isn’t getting updated in this loop?
Public Sub Print_all_to_pdf()
Dim i As Integer
Dim cur_val As Integer
Dim props_cnt As Integer
Dim image_path As Variant
Dim map_path As Variant
Application.ScreenUpdating = False
cur_val = Range("Selected_Property").Value
props_cnt = Range("Max_Property").Value
For i = cur_val To props_cnt
Range("Selected_Property").Value = i
image_path = Range("Image_Path").Value
map_path = Range("Map_Path").Value
ActiveSheet.Shapes.Range(Array("Image")).Select
With Selection.ShapeRange.Fill
.Visible = msoTrue
.UserPicture _
image_path
.TextureTile = msoFalse
.RotateWithObject = msoTrue
ActiveSheet.Shapes.Range(Array("Map")).Select
With Selection.ShapeRange.Fill
.Visible = msoTrue
.UserPicture _
map_path
.TextureTile = msoFalse
.RotateWithObject = msoTrue
Call export_report_as_pdf
Next i
Range("Selected_Property").Value = cur_val
Application.ScreenUpdating = True
End Sub
解决方案
推荐阅读
- java - 使用 MyBatis。如何在一个表中映射两条不同的记录,然后在加入该表时构造一个查询结果?
- angular - Angular中的HttpInterceptor不重试失败的请求
- resize - 更改客户端窗口的高度?
- javascript - 如何更改 fullcalendar v5 中的空事件选择内容?
- linux - google.golang.org/grpc 未正确安装,PeerCertificates[0].URIs 未定义(类型 *x509.Certificate 没有字段或方法 URI)
- python-3.x - drf CustomUser 匹配查询不存在
- python - 尝试使用硒单击网页上的元素
- html - 选择控件的自动换行在 Firefox 中不起作用但在 Chrome 中起作用
- javascript - 基于首字母的过滤器搜索
- python - 如何通过模糊匹配找到文本重用?