我想从指定位置的指定位置导入指定文件夹中的所有工作簿中的宏文件,并且希望在每个工作簿上运行宏,我可以通过所提到的代码成功地在所有工作簿中导入它下面但不能运行这些宏。在VBA中运行导入的宏的问题
Sub RecursiveFolders()
Dim FileSys As Object
Dim objFolder As Object
Dim objSubFolder As Object
Dim objFile1 As Scripting.File
Dim wkbOpen As Workbook
Dim szImportPath As String
Dim objFSO As Scripting.FileSystemObject
Dim cmpComponents As VBIDE.VBComponents
Set objFSO = New Scripting.FileSystemObject
Set FileSys = CreateObject("Scripting.FileSystemObject")
Set objFolder = FileSys.GetFolder("C:\Users\Yashika Vaish\Desktop\testform")
Application.ScreenUpdating = False
For Each objSubFolder In objFolder.SubFolders
For Each objFile In objSubFolder.Files
Set wkbOpen = Workbooks.Open(Filename:=objFile)
szImportPath = FolderWithVBAProjectFiles & "C:\Macros"
Set cmpComponents = wkbOpen.VBProject.VBComponents
For Each objFile1 In objFSO.GetFolder(szImportPath).Files
If (objFSO.GetExtensionName(objFile1.Name) = "cls") Or _
(objFSO.GetExtensionName(objFile1.Name) = "frm") Or _
(objFSO.GetExtensionName(objFile1.Name) = "bas") Then
cmpComponents.Import objFile1.Path
End If
Next objFile1
Application.DisplayAlerts = False
MsgBox "Import is ready"
Application.Run "HeaderChange_User_Financial_Input"
Application.Run HeaderChange_User_Financial_Input
Application.Run HeaderChange_User_Operation_Input
Application.Run SelectRangeUnitMap
Application.Run reportingunitmap
Application.Run HeaderChange_Finacial_Standard
Application.Run HeaderChange_Operation_Standard
wkbOpen.Close savechanges:=True
Next
Next
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
此代码给我弹出无法运行宏,
它可能不可用或所有的宏被禁用
但没有密码保护所以为什么我不能运行宏,请帮忙。
您是否将宏安全设置设置得太高?在'Excel 2010' - 'File'〜'Options'〜'Trust Center'〜'Trust Center Settings'〜'Macro Settings'〜确保_Disable所有没有notification_的宏没有设置。我通常建议通过notification_set禁用所有的宏。 –