VBA缺少Worksheet.Range作为值,并不断获取未设置的Object变量(错误91)

时间:2018-09-20 19:39:06

标签: excel vba visio

Public Sub InputData(var)
Dim WB As Workbook
Dim FilePath As String
FilePath = "C:\Users\Jordan.Jennings\Desktop\Programs{}\Test.xlsx"
WB = Workbooks.Open(FilePath)
ibox = 1
E = 8.5
N = 10
W = 7.5
S = 9.75
Do Until ibox = var
    Set I = ActivePage.DrawRectangle(E, N, W, S)
    I.Text = WB.Worksheets("Sheet1").Range("A1").Value
    N = N - 0.25
    S = S - 0.25
    ibox = ibox + 1
Loop
End Sub

好吧,我已经尝试了很多事情-我想做的是在visio中用Excel文档中的文本绘制一堆盒子,当我执行worksheets(“ Sheet1”)时。范围不出现一个选项,我抛出错误91请帮助我在这里茫然

1 个答案:

答案 0 :(得分:1)

WBWorkbook对象引用。

WB = Workbooks.Open(FilePath)

您不能分配这样的对象引用。

Set WB = Workbooks.Open(FilePath)

那应该解决它。