vba - 在其他单元格之后复制图片范围名称
问题描述
我正在尝试复制 B 列中的图片单元格,并将它们命名为第 1 列中的值。我有有效的代码,除了它不断给图片提供错误的名称。令人费解的是,有时它可以完美运行,而其他时候则不能。
我试图根据发布的 CopyPicture 命令示例拼凑一个例程。我把它贴在下面。
是的,我是 VBScript 的新手。要温柔。;-)
Sub makepic()
Dim path As String
path = "C:\BP\BP2020\JPGs\"
Dim CLen As Integer
Dim cntr As Integer
cntr = 1
Dim rgExp As Range
Dim CCntr As String
CString2 = "A1:A6"
Set rgExp2 = Range(CString2)
CString = "B1:B6"
Set rgExp = Range(CString)
For I = 1 To rgExp.Cells.Count Step 1
CCntr = rgExp2.Cells(I).Value
rgExp.Cells.Cells(I).Font.Size = 72
rgExp.Cells.Cells(I).CopyPicture Appearance:=xlScreen, Format:=xlBitmap
rgExp.Cells.Cells(I).Font.Size = 14
''' Create an empty chart with exact size of range copied
CLen = Len(rgExp.Cells.Cells(I).Value)
CWidth = CLen * 85
With ActiveSheet.ChartObjects.Add(Left:=1600, Top:=rgExp.Top, _
Width:=CWidth, Height:=50)
.Name = "ChartVolumeMetricsDevEXPORT"
.Activate
End With
''' Paste into chart area, export to file, delete chart.
If CCntr <> "" Then
ActiveChart.Paste
Selection.Name = "pastedPic"
ActiveSheet.ChartObjects("ChartVolumeMetricsDevEXPORT").Chart.Export (path + CCntr & ".jpg")
ActiveSheet.ChartObjects("ChartVolumeMetricsDevEXPORT").Delete
End If
cntr = cntr + 1
Next
End Sub
同样,我希望 - 例如 - 单元格 B1 内容的图片具有 A1 内容的名称。我尝试制作 A1:B4 范围(例如),但这给了我 8 张照片。我最终决定尝试制作 2 个范围,但这也不起作用。
解决方案
推荐阅读
- python-2.7 - Python:打开一组字典作为数据框
- python - 无法获取 TensorFlow 的卷积算法
- python - re.sub 在标点符号和单词之间放置空格,单词以标点符号开头或结尾
- android - 使用 Android DateUtils 的部分相对日期和时间
- sql-server - 将数据类型 nvarchar 转换为数值时出错。尝试转换和替换
- jquery - 选择器以特定字母开头,后跟任意数字
- python - 根据行和列的值填充 NaN 值
- javascript - 如何在 Wordpress 上添加可见的编辑快捷方式
- sas - 使用 set 语句选择多个具有模式的文件
- python - Bokeh 和 Django:Bokeh 仅检索经过身份验证的 Django 用户的数据