问题描述
我有一个代码,可以在excel列表中输入信息.我希望能够创建一个文件夹-我正在使用下面的代码.问题是我希望它能为我所有的同事(不仅仅是我)工作.有人可以帮忙找到我哪里出错了吗?请注意,这是部分代码,该错误发生在MkDir行上.感谢您的提前帮助!
I have a code where you input information in an excel list. I want to be able to create a folder - I am using the code below. The issue is that I want it to work for all my colleagues (not just me). Can someone please help find where I am getting an error? Note this is a partial code, the error is happening on the MkDir line. Thanks for your help in advance!
Dim Startupfolder As String
Startupfolder = Startup_Name.Value
MkDir Environ$("Userprofile") & "\nc Dropbox\investment oportunities\ & "Startupfolder"
推荐答案
问题出在你的引号上.试试这个:
The problem is where you put your quotes. Try this:
MkDir Environ$("Userprofile") & "\nc Dropbox\investment oportunities\" & Startupfolder
Startupfolder是可变的,因此您不希望在引号内
Startupfolder is variable, so you don't want that within quotes
更多信息
如果您的文件夹放在一个尚不存在的文件夹中,它将失败.如果它已经存在,它也会失败.
More info
If your folder is put in a not yet existing folder, it will fail. It will also fail if it already exists.
尝试以下方法:
Sub MakeDir()
CreateFolder Environ$("Userprofile") & "\nc Dropbox"
CreateFolder Environ$("Userprofile") & "\nc Dropbox\investment oportunities"
CreateFolder Environ$("Userprofile") & "\nc Dropbox\investment oportunities\" & Startupfolder
End Sub
Sub CreateFolder(Folder)
If Len(Dir(Folder, vbDirectory)) = 0 Then
MkDir Folder
End If
End Sub
这篇关于如何为不同用户使用路径可变的MkDir的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!