1
我正在运行访问VBA代码来打开Excel,对一些图进行小修改并将它们保存为bmp。 98%的时间运行良好。然而,每一个现在,然后我得到的线“Selection.Left = 320
”以下错误:运行时错误91 - 访问excel交互
运行时错误“91”:
对象变量或与块变量未设置
二小问题,我我想解决的是,每次我运行这个宏后,每次打开其他excel文档时,这个宏使用的excel文档也会自动打开,不知道为什么。
Private Sub Form_Open(Cancel As Integer)
If [Forms]![Detail]![Qualification Documents].[Value] <> "" Then
Dim octopus As String
octopus = ([Forms]![Detail]![Qualification Documents].[Value])
Set objExcelApp = New Excel.APPLICATION
Dim ws As Worksheet
Set wb = objExcelApp.Workbooks.Open(FileName:="Path\" & octopus & " ", ReadOnly:=True)
'Set ws = wb.Sheets("SheetX")
wb.APPLICATION.DisplayAlerts = False
wb.Sheets("SheetX").Select
x = 1
While x < 4
wb.ActiveSheet.ChartObjects(x).Activate
With wb.ActiveChart.Parent
.Height = 500 ' resize
.Width = 1200 ' resize
.Top = 100 ' reposition
.Left = 100 ' reposition
End With
On Error GoTo here:
here:
wb.ActiveChart.Legend.Select
Selection.Left = 320
Selection.Top = 380
Selection.Height = 35
Selection.Width = 600
wb.ActiveChart.Export "X:\Assembly\CAPEX 2013\drilling database\graph" & x & ".bmp"
x = x + 1
Wend
wb.Close
Set objExcelApp = Nothing
End If
End Sub
感谢您的回答。 Howerver,我已经解决了这个问题,所以我无法测试你对特定问题的建议。 – LuTze