Excel VBA-Mkdir返回找不到的路径

时间:2019-03-02 15:12:58

标签: excel vba

我正在尝试创建一个宏,该宏将允许用户选择一些照片并将其复制到特定的文件夹中。该文件夹应使用日期和组合框中的值创建。

当我尝试运行代码时,在MKdir函数上收到运行时错误“找不到路径”,我检查了该点,并且之前的所有路径都是正确的。

关于导致此错误的原因有什么想法?

谢谢

'Add photos
Private Sub CommandButton3_Click()

Dim fileExplorer As Integer
Dim photo As String
Dim Path1 As String
Dim P As String
Dim FSO As Scripting.FileSystemObject

Application.FileDialog(msoFileDialogOpen).AllowMultiSelect = True
fileExplorer = Application.FileDialog(msoFileDialogOpen).Show

If fileExplorer <> 0 Then

   photo = Application.FileDialog(msoFileDialogOpen).SelectedItems(1)

Else

MsgBox ("None file has been selected")

Exit Sub

End If

dt_value = DTPicker1.Value
Syst = ComboBox1.Value

Path1 = dt_value & "-" & Syst

P = "C:\Folder" & "\" & Path1

MkDir (P)

Set FSO = New Scripting.FileSystemObject
Call FSO.CopyFile(photo, P, False)

MsgBox ("Your photos have been imported")

End Sub

0 个答案:

没有答案