0

改写我的问题:

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 Chain\Weekly Rpts Supplier and Buyer\" & path & "\SUPPLIER_01_00028257_KIK CUSTOM PRODUCTS GAINSVILLE_21-OCT-12.xls")

路径是单元格中的日期。当此单元格更改时,我希望目录根据路径更改。

4

1 回答 1

3

两件事情

  1. 将路径声明为字符串而不是范围。
  2. 在路径中使用之前替换日期中的“\”

这是你正在尝试的吗?

Dim path As String
path = shPivot.Range("E12").Value
Set wkbFrom = Workbooks.Open("S:\_Supply Chain\Weekly 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 Chain\Weekly 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 Chain\Weekly Rpts Supplier and Buyer\" & _
              Trim(path) & _
              "\SUPPLIER_01_00028257_KIK CUSTOM PRODUCTS GAINSVILLE_21-OCT-12.xls")
于 2012-10-25T19:59:42.313 回答