我正在尝试将文件打开到特定标签中,但我很挣扎。我知道位置有问题。我尝试添加方括号和其他格式来修复位置,但无济于事。
strPath = "G:\Budgets and Financial\CLT Budget Templates\"
strFile = "Belle Grove Manor.xlsx"
strSheet = "Sheet1"
strRng = Range("E2").Address(2, 5, xlR1C1)
strRef = "'" & strPath & "[" & strFile & "]" & strSheet & "'!" & strRng
Workbooks.Open (strRef)
答案 0 :(得分:1)
这行吗?
Sub openWB()
strPath = "G:\Budgets and Financial\CLT Budget Templates\"
strFile = "Belle Grove Manor.xlsx"
strSheet = "Sheet1"
strRng = "E2"
strRef = strPath & strFile
Dim newWB As Workbook
Set newWB = Workbooks.Open(strRef)
newWB.Sheets(strSheet).Select
newWB.Sheets(strSheet).Range(strRng ).Select
End Sub
答案 1 :(得分:0)
这是一个附加答案,可以防止工作表被隐藏。
Sub OpenAndSheet()
Dim strPath As String: strPath = "G:\Budgets and Financial\CLT Budget Templates\Belle Grove Manor.xlsx"""
Dim strSheet As String: strSheet = "Sheet1"
Dim strRng As String: strRng = "E2"
Dim WBK As Workbook: Set WBK = Workbooks.Open(strRef)
Dim WS As Worksheet: Set WS = WBK.Sheets(strSheet)
With WS
.Visible = xlSheetVisible
.Activate
.Range(strRng).Select
End With
End Sub