Mac Excel v16.16.7-尝试使用宏将工作表名称作为文件名的xlsm文件的活动工作表导出到csv。
我知道沙盒问题,并以为我可以使用GrantAccessToMultipleFiles解决它们,但是下面的确切宏会带来三种不同的结果:
Sub SaveAsCSV()
Dim strName As String
Dim fileAccessGranted As Boolean
Dim filePermissionCandidates
filePermissionCandidates = Array(ThisWorkbook.Path & Application.PathSeparator & ActiveSheet.Name & ".csv")
fileAccessGranted = GrantAccessToMultipleFiles(filePermissionCandidates)
If fileAccessGranted = True Then
Application.ScreenUpdating = False
strName = ThisWorkbook.Path & Application.PathSeparator & ActiveSheet.Name & ".csv"
ActiveSheet.Copy 'copy the sheet as a new workbook
ActiveWorkbook.SaveAs Filename:=strName, FileFormat:=xlCSV
ActiveWorkbook.Close SaveChanges:=False
Application.ScreenUpdating = True
MsgBox "File has been Created and Saved as: " & vbCr & strName, , "Copy & Save Report"
End If
End Sub
我希望对结果为何有所不同有所了解。谢谢!