0

我试图访问位于同一文件夹中的另一个工作簿中的图表和图片以及图表。这是我的代码。

wbname = Worksheets("Sheet1").Range("A1:A1").Value
wsname = Worksheets("Sheet1").Range("A2:A2").Value
MsgBox wbname
wbname = ThisWorkbook.Path & "\" & wbname    
MsgBox "reached here"
MsgBox "HI"
MsgBox Workbooks("C:\charts\1.xls").Sheet("L1-XO PGT ScoreCard").Range("A1:A1").Value
Set aWorkSheet = Workbooks("C:\charts\1.xls").Sheet("L1-XO PGT ScoreCard")
sCurrentSheet = aWorkSheet.Name
MsgBox "Shapes count " + CStr(aWorkSheet.Shapes.Count)
For iIndex = 1 To aWorkSheet.Shapes.Count
Set aShape = aWorkSheet.Shapes(iIndex)
MyPicture = aShape.Name
MsgBox aShape.Name + " Name, " + Str(aShape.Type)
If Left(aShape.Name, 7) = "Picture" Then
With aShape
PicHeight = .Height
PicWidth = .Width
End With
Set aChart = ActiveWorkbook.Charts.Add
ActiveWorkbook.ActiveChart.Location Where:=xlLocationAsObject, Name:=sCurrentSheet
iShapeCount = aWorkSheet.Shapes.Count
Set aShapeChart = aWorkSheet.Shapes(iShapeCount)
MyChart = aShapeChart.Name      '"Chart " & Str(aWorkSheet.Shapes.Count)
aShapeChart.Width = PicWidth
aShapeChart.Height = PicHeight
sChartJpg = sChartJpg & aShapeChart.Name & ".jpg"
With aWorkSheet
aShape.Copy
With ActiveChart 'aChart
.ChartArea.Select
.Paste
End With
.ChartObjects(iIndex).Chart.Export Filename:=sChartJpg, FilterName:="jpg",                    Interactive:=True
aShapeChart.Cut
End With
Application.ScreenUpdating = True
MsgBox "Completed."
Exit Sub
End If
Next
MsgBox "Completed."Exit Sub
ErrHandler:
MsgBox "Error # " & CStr(Err.Number) & " " & Err.Description & " " & Err.Source
Err.Clear   ' Clear the error.
 End Sub

显示“HI”警报框后,它直接显示 Completed 测试框而不显示 TestBOX 警报“MsgBox Workbooks("C:\charts\1.xls").Sheet("L1-XO PGT ScoreCard").Range ("A1:A1").Value" ... 也不是从工作簿中提取图像。有人可以帮忙吗

4

1 回答 1

2

您必须打开工作簿 - 您的大部分代码无法在关闭的工作簿上运行。

于 2012-12-08T08:38:09.890 回答