0
Sub openwb()

Dim x260path As String

x260path = "E:\sarath\PTMetrics\20131002\D8 L538-L550 16MY\D8 L538-L550_16MY_Powertrain Metrics_" & Format(Date, "YYYYMMDD") - 1

Workbooks("x260path").Activate

ActiveWorkbook.SaveAs ["E:\sarath\PTMetrics\20131002\D8 L538-L550 16MY\D8 L538-L550_16MY_Powertrain Metrics_" & Format(Date, "YYYYMMDD")]

Debug.Print x260path

End Sub

在这里,当我执行时,错误提示“下标超出范围”。它出现在第 4 行。当我使用“工作簿”来声明“x260path”而不是字符串时,它在第 3 行显示另一个错误说“对象变量或未设置块变量”。你能帮忙吗?为什么会这样?

4

1 回答 1

0

要激活工作簿,您需要设置对工作簿名称的引用,而不是工作簿的完整路径和名称。因此,从你的x260path变量中你只需要得到名字。有几种可能的方法可以做到这一点。这是我刚刚想到的一个:

Dim x260path As String

x260path = "E:\sarath\PTMetrics\20131002\D8 L538-L550 16MY\D8 L538-L550_16MY_Powertrain Metrics_" & Format(Date, "YYYYMMDD") - 1

Dim x260name As String
x260name = Split(x260path, "\")(UBound(Split(x260path, "\")))

Workbooks(x260name).Activate

'the rest of your code here
于 2013-10-02T10:39:52.017 回答