我被要求帮助excel文件引用另一个文件但失败的用户。查看问题,他们在子文件夹中有一个感叹号此时他们无法重命名文件夹或移动文件。
对建议开放
这些例子起作用
= 'C:\ TEMP2 \ excelTest \ [GoodFile.xlsx] Sheet 1中'!A1
= 'C:\ TEMP2 \ excelTest \ [!为File.xlsx] Sheet 1中'!A1
这失败
= 'C:\ TEMP2 \ excelTest \坏文件夹\ [GoodFile.xlsx] Sheet 1中'!A1
我尝试使用VBA打开文件,但结果相似。
Public Sub testVBA()
Dim FileName As String
Dim wbTarget As Workbook
Dim wsTarget As Worksheet
'Works
FileName = "C:\temp2\excelTest\GoodFile.xlsx"
'Fails
'FileName = "C:\temp2\excelTest\Bad!Folder\GoodFile.xlsx"
' escaping the ! also fails
'FileName = "C:\temp2\excelTest\Bad" & Chr(34) & "Folder\GoodFile.xlsx"
Set wbTarget = Workbooks.Open(FileName)
Set wsTarget = wbTarget.Worksheets("Sheet1")
MsgBox (wsTarget.Range("A1"))
End Sub