我有一个电子表格,单击一个按钮将通过将所有内容复制/粘贴到新工作簿来复制自身,并使用依赖于某些变量值的名称保存文件(从电子表格中的单元格中获取).我目前的目标是让它将表单保存在不同的文件夹中,具体取决于客户端名称的名称(变量中保存的单元格值),而这在第一次运行时起作用,之后我收到错误.
代码检查目录是否存在,如果不存在则创建它.这可行,但在创建后,再次运行它会抛出错误:
运行时错误75 - 路径/文件访问错误.
我的代码:
Sub Pastefile()
Dim client As String
Dim site As String
Dim screeningdate As Date
screeningdate = Range("b7").Value
Dim screeningdate_text As String
screeningdate_text = Format$(screeningdate, "yyyy\-mm\-dd")
client = Range("B3").Value
site = Range("B23").Value
Dim SrceFile
Dim DestFile
If Dir("C:\2013 Recieved Schedules" & "\" & client) = Empty Then
MkDir "C:\2013 Recieved Schedules" & "\" & client
End If
SrceFile = "C:\2013 Recieved Schedules\schedule template.xlsx"
DestFile = "C:\2013 Recieved Schedules\" & client & "\" & client & …
Run Code Online (Sandbox Code Playgroud)