Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
excel vba代码,用于检查文件夹是否存在,如果不存在,则创建文件夹_Excel_Vba_Macos_Directory - Fatal编程技术网

excel vba代码,用于检查文件夹是否存在,如果不存在,则创建文件夹

excel vba代码,用于检查文件夹是否存在,如果不存在,则创建文件夹,excel,vba,macos,directory,Excel,Vba,Macos,Directory,我是excel vba编码的新手,并尝试创建excel工作表范围的pdf。我的代码在windows操作系统中运行良好,但在Mac操作系统中却不起作用。代码如下: ` Sub-GeneratePDF() 将wsA设置为工作表 将wbA设置为工作簿 作为字符串的Dim strTime 将strName设置为字符串 将strPath设置为字符串 作为字符串的Dim strFile 将strPathFile设置为字符串 Dim myFile作为变量 暗淡的丝绒名称为字符串 Dim SelectedRan

我是excel vba编码的新手,并尝试创建excel工作表范围的pdf。我的代码在windows操作系统中运行良好,但在Mac操作系统中却不起作用。代码如下: `

Sub-GeneratePDF()
将wsA设置为工作表
将wbA设置为工作簿
作为字符串的Dim strTime
将strName设置为字符串
将strPath设置为字符串
作为字符串的Dim strFile
将strPathFile设置为字符串
Dim myFile作为变量
暗淡的丝绒名称为字符串
Dim SelectedRange作为范围
使用此工作簿。工作表(“模”)
.激活
.Range(.Cells(1,1),.Cells(33,10))。选择
Selection.Name=“SelectedRange”
以
关于错误转到错误处理程序
设置wbA=ActiveWorkbook
设置wsA=ActiveWorkbook.Worksheets(“模”)
strTime=格式(现在(),“ddmmyyyy\\u hhmm”)
'获取活动工作簿文件夹(如果已保存)
strPath=wbA.Path
如果strPath=“”,则
strPath=Application.DefaultFilePath
如果结束
strPath=strPath&“\”
VelleName=ThisWorkbook.Worksheets(“数据库”).Range(“B”和Desiredrow)和“”和ThisWorkbook.Worksheets(“数据库”).Range(“C”和Desiredrow)
'替换图纸名称中的空格和句点
strName=Replace(VelleName,“,”替换)
strName=Replace(strName,“.”,“”)
strName=替换(strName,“-”,“”)
strName=Replace(strName,“/”,“”)
'为savng文件创建默认名称
strFile=strName&“&&strTime&.pdf”
strPathFile=strName&“&”strTime
'为文件选择文件夹

如果Dir(strPath&Application.PathSeparator&“forme”,vbDirectory)=“”,则“我使用此代码并将其添加到检查文件是否存在

'Only Change code Here
Sub Verify()
    Dim myPath As String
    myPath = "C:\abc" '<--------This line
    If Not PathExist(myPath) Then MkDir (myPath)
End Sub

Private Function PathExist(path_ As String) As Boolean
    On Error GoTo ErrNotExist
    Call ChDir(path_)
   PathExist = True
   Exit Function
ErrNotExist:
    PathExist = False
End Function

Private Function FileExist(filePath_ As String) As Boolean
    FileExist = Len(Dir(filePath_)) <> 0
End Function
“仅在此处更改代码
子验证()
将myPath设置为字符串

myPath=“C:\abc”'欢迎任何帮助。如果有人给我的源代码链接,我可以学习vba的MacOS。非常感谢。您会遇到什么错误显示?它在mkdir()行中的错误我也在代码中对此进行了注释。我知道它在mkdir()行中,但它在该行上运行时会显示什么错误?看看在MacOS中vba是如何被沙盒化的
'Only Change code Here
Sub Verify()
    Dim myPath As String
    myPath = "C:\abc" '<--------This line
    If Not PathExist(myPath) Then MkDir (myPath)
End Sub

Private Function PathExist(path_ As String) As Boolean
    On Error GoTo ErrNotExist
    Call ChDir(path_)
   PathExist = True
   Exit Function
ErrNotExist:
    PathExist = False
End Function

Private Function FileExist(filePath_ As String) As Boolean
    FileExist = Len(Dir(filePath_)) <> 0
End Function