重新单词我的问题:
Sub Path()
Dim path As Range
Dim shPivot As Worksheet
Set shPivot = ActiveWorkbook.Sheets("Pivot")
Set path = shPivot.Range("E12").Value
Set wkbFrom = Workbooks.Open("S:_Supply ChainWeekly Rpts Supplier and Buyer" & path & "SUPPLIER_01_00028257_KIK CUSTOM PRODUCTS GAINSVILLE_21-OCT-12.xls")
路径是单元格中的日期。当此单元格更改时,我希望目录根据路径更改。
两件事
- 将路径声明为字符串,而不是范围。
- 在路径中使用该日期之前替换" "
这是您正在尝试的吗?
Dim path As String
path = shPivot.Range("E12").Value
Set wkbFrom = Workbooks.Open("S:_Supply ChainWeekly Rpts Supplier and Buyer" & _
format(path,"DD-MM-YYYY") & _
"SUPPLIER_01_00028257_KIK CUSTOM PRODUCTS GAINSVILLE_21-OCT-12.xls")
随访
在这种情况下,请使用此
Dim path As String
path = shPivot.Range("E12").Value
Set wkbFrom = Workbooks.Open("S:_Supply ChainWeekly Rpts Supplier and Buyer" & _
path & _
"SUPPLIER_01_00028257_KIK CUSTOM PRODUCTS GAINSVILLE_21-OCT-12.xls")
如果有任何不必要的空间,则必须使用TRIM
Dim path As String
path = shPivot.Range("E12").Value
Set wkbFrom = Workbooks.Open("S:_Supply ChainWeekly Rpts Supplier and Buyer" & _
Trim(path) & _
"SUPPLIER_01_00028257_KIK CUSTOM PRODUCTS GAINSVILLE_21-OCT-12.xls")