VBA Application.Run错误(宏可能在此工作簿中不可用,或者所有宏都被禁用)

您所在的位置:网站首页 excel提示宏不可用或全部禁用 VBA Application.Run错误(宏可能在此工作簿中不可用,或者所有宏都被禁用)

VBA Application.Run错误(宏可能在此工作簿中不可用,或者所有宏都被禁用)

2024-03-02 13:42| 来源: 网络整理| 查看: 265

新问题:

我最初的问题已经得到了回答,解决方案也非常好。然而,这导致了另一个问题。下面是流程:

macroFile1 Sub1 (调用macroFile2 Sub3并传递参数) -> macroFile2 Sub3 (执行一些处理,并期望向macroFile1 Sub1返回多个值)

macroFile1 Sub1能够调用macroFile2 Sub3,但macroFile2 Sub3无法返回值。我尝试了以下方法:

method1:

'(macroFile1) returnCodes = Application.Run("'" & macroFileName & "'!pasteCapture", _ thisWorkbookName, selectedFile, cmntText, workingSheet, cmntRowNum, cmntColNum, imgRowNum, imgColNum, size, clrTyp)

执行时出错:编译错误:无法赋值给数组

method2:

'(macroFile1) Sub1 '(This sub is going to call macroFile2 Sub3, and macroFile2 Sub3 is going to do some process, and then return values to the following Sub2.) Application.Run "'" & macroFileName & "'!pasteCapture", _ thisWorkbookName, selectedFile, cmntText, workingSheet, cmntRowNum, cmntColNum, imgRowNum, imgColNum, size, clrTyp 'thisWorkbookName is the absolute path of the file containing macroFile1. I am passing this to macroFile2 Sub3 so that I can call macroFile1 Sub2 from macroFile2 Sub3. End Sub Sub2 '(I wrote this sub so that I can receive return codes from macroFile2 Sub3. This sub is right below macroFile1 Sub1.) Sub getReturnCodes(extError, fileNotFound, opnError, worksheetNotFound, rowNotNumeric, rowOutOfScope, colNotNumeric, colOutOfScope, sizeNotNumeric, sizeOutOfScope, incorrectClrTyp, success) If success = 0 Then MsgBox "Successful", vbOKOnly Else MsgBox "Error", vbOKOnly End If End Sub '(macroFile2) Sub3 '(This sub will receive multiple arguments from macroFile1 Sub1, process them, and call macroFile1 Sub2 to pass multiple return values.) 'Some process... Application.Run "'" & calledBy & "'!getReturnCodes", _ extError, fileNotFound, opnError, worksheetNotFound, rowNotNumeric, rowOutOfScope, colNotNumeric, colOutOfScope, sizeNotNumeric, sizeOutOfScope, incorrectClrTyp, success End Sub

执行时出错:宏可能在此工作簿中不可用,或者所有宏都可能被禁用

请帮帮忙。我希望将多个值作为返回值传递给macroFile1。我被允许将它们传递给Sub1或Sub2。

原问题:

从另一个宏文件调用宏时出现错误。我已经看到了很多类似的帖子,并尝试了建议的解决方案;然而,我仍然得到了错误。

代码如下:

'The following program is supposed to call another program Sub screenCapture_Click() Dim selectedFile As String 'Full path of the selected file Const rowNum As Integer = 1 Const colNum As Integer = 1 Const workingSheet As Integer = 1 Const size As Variant = 100 Const clrTyp As Variant = 1 With Application.FileDialog(msoFileDialogOpen) .AllowMultiSelect = False If .Show = False Then Exit Sub Else selectedFile = .SelectedItems(1) Application.Run ("'ScreenCapture子プログラム.xlsm'!pasteCapture (" & selectedFile & "," & rowNum & "," & colNum & "," & workingSheet & "," & size & "," & clrTyp & ")") ** 'This is where the error occors. Application.Run is able to open 'ScreenCapture子プログラム.xlsm', but it is not able to call the macro...** End If End With End Sub 'The above program calls the following program Sub pasteCapture(selectedFile, rowNum, colNum, workingSheet, size, clrTyp) Dim capture As Image 'Captured image Dim capturesFile As Workbook EnterCommentUserForm.Show . . . End Sub

你能帮帮我吗?



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3