2
Sub openwb()

Dim sb As String

Dim wb, dwb As Workbook

Dim ws As Worksheet

Set dwb = ActiveWorkbook

Set ws = dwb.Sheets("Home")

sb = ws.Range("F4").Value

Set wb = sb&"_Powertrain Metrics_" & (Format(Date, "YYYYMMDD") & ".xlsm")

Debug.Print wb

End Sub

在第 8 行,该部分"_Powertrain Metrics_"突出显示并显示“编译错误:预期语句结束”。你能告诉我这里有什么问题吗?我使用的字符串有什么问题吗?

4

1 回答 1

1

一个。改变

Dim wb, dwb As Workbook

Dim wb As Workbook, dwb As Workbook

在 VBA 中,您必须显式声明变量,否则它们将被视为变体。

。改变

Set wb = sb&"_Powertrain Metrics_" & (Format(Date, "YYYYMMDD") & ".xlsm")

Set wb = Workbooks.Open(sb & "_Powertrain Metrics_" & Format(Date, "YYYYMMDD") & ".xlsm")

你错过了SPACE之前和之后&

于 2013-10-05T05:59:53.870 回答