修改路径

时间:2015-02-26 17:29:07

标签: excel vba excel-vba path

我有这个代码,打开所有文件。路径写在单元格(1,1)中。最后在路径的最后我必须放置\,所以我想知道在路径的末尾是否有可以自动执行的操作。

Sub openfiles()
   Dim directory As String, fileName As String, sheet As Worksheet, i As  Integer, j As Integer, finalRow As Integer
   Application.ScreenUpdating = False
   directory = Cells(1, 1)
   fileName = Dir(directory & "*.xl??")
   Do While fileName <> ""
      Workbooks.Open (directory & fileName)
      fileName = Dir()

   Loop
   Application.ScreenUpdating = True

End Sub

1 个答案:

答案 0 :(得分:2)

在字符串

的末尾添加“\”
directory = Cells(1,1).Value & "\"