vba不能宏的运行需要vba环境支持?

【分享成果,随喜正能量】重复,而得专注,心无旁骛,乃成其大,成其精。人这一生,最幸福的事,就是投入百分百的热爱,做自己喜欢的事,并不断努力,才不枉此生。。《VBA之Excel应用》是非常经典的,是我推出的第七套教程,定位于初级。这套教程从简单的录制宏开始讲解,一直到窗体的搭建,内容丰富,实例众多。大家可以非常容易的掌握相关的知识,这套教程共三册,十七章,都是我们在利用EXCEL工作过程中需要掌握的知识点,希望大家能掌握利用。今日讲解的内容是“VBA之EXCEL应用”: 如何运行VBA代码第三节
利用运行按钮,从模块(Module)运行代码作为Excelvba的初学者,您可能会发现很难决定将VBA代码放在哪里。“创建宏”一节说明了如何通过单击命令按钮来运行代码,同时我们也提到利用一个自选图形作为运行按钮的实例,这章将讲解一个实例代码,放在标准模块中,然后讲解从模块中运行代码。1
打开Visual Basic编辑器我们在上面的章节中已经知道了如何打开一个Visual Basic编辑器了,这个编译器我们俗称为VBE窗口。我们打开它:2
建立新的模块(Module)在主界面上点击“插入”,弹出的对话框中我们选择“模块”,点击。这些动作将表示我们将在后台插入一个模块,这个模块是标准模块,这个模块中我们将利用VBA的代码来驱动一些对象,达到我们的一些目的,这种目的是以提高工作效率,提高自动化操作为目的的。如下面的操作界面:3
创建一个名为Mynz的过程(宏)我们先看一下上面操作后的界面,如下:此时,我们添加了一个标准模块“模块1”,在录入代码区域,我们录入下面的代码:Sub mynz()End Sub此时我们将创建一个mynz过程:注意:过程可以是SUB过程,也可以是FOUNTION函数。4
在过程中添加我们的代码我们在模块中添加下面的代码:Sub mynz()
Sheets("Sheet3").Select
Cells.Interior.ColorIndex = 28End Sub代码截图:代码解读:上面的MYNZ过程将工作表的背景色更改为青色。注意:ColorIndex编号为28表示青色,当然,你可以使用其他的代码表示不同的颜色。5
执行编译好的代码要运行该过程,一般可以用以下两种方法:方法一:在如下的界面,单击“宏”,弹出的对话框中选择宏名“mynz”,最后点击“执行”。这样就可以执行我们刚才编写的代码了。方法二:这种方法是利用我们在第一讲中讲的利用自定义图形作为我们的运行按钮,关于如何建立运行按钮,这里不再多讲,大家可以回过头再看看前面第一章的内容,下面我们讲解如何将这个运行按钮关联到我们的代码。如下图:选中“运行”按钮,右键,在弹出的对话框中点击“指定宏”,弹出下面的对话框:在弹出的对话框中,我们选择已经建立的过程“mynz”,点击确定。最后我们回到工作表界面,当鼠标移动到“运行”按钮时会变成手型,点击一下,看看代码的执行效果:这个时候,整个工作表的界面变成了青色。今日内容回向:
1)如何实现运行模块中的代码?
2)如何改变工作表的颜色?
3)
Cells.Interior.ColorIndex = 28代表什么意思?本讲内容参考程序文件:工作簿01.xlsm我20多年的VBA成果全在下面的资料中:【分享成果,随喜正能量】只要有结缘,就会有无限的未来。结缘,使我们的人生更宽阔,命运更平坦;积德结缘,才是人生幸福的根源。。 }
本文介绍了Excel VBA调试器停止运行,没有错误或警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!问题描述在尝试测试一些代码时,我遇到了一个我不记得遇到过的问题。当我单步执行代码时,它在ClearContents行之后停止……没有错误,没有警告,什么都没有。While trying to test some code, I am having an issue that I don't recall running into before.
When I step through the code it halts after the ClearContents line...there is no error, no warning, nothing.Public Sub CreateCurMth(wsCur As Worksheet)
Dim iData As Integer, iRow As Integer
Dim wbData As Workbook
On Error GoTo err_here
iRow = wsCur.Cells(Rows.Count, 1).End(xlUp).Row
wsCur.Range("A10:X" & iRow).ClearContents
'<----- Fails after this line
'Assume that file is already open
Set wbData = Workbooks("qReport.xlsx")
... etc
err_here:
Beep
End Sub
wsCur是在调用子项中分配的工作表。该代码准确地将iRow返回为wsCur上最后使用的行。同样,内容也被清除了……这样行就可以执行了。死后没有播放哔声。我在Beep上也有一个断点,而且从来没有命中。wsCur is a worksheet that is assigned in the calling sub.
The code accurately returns the iRow as the last used row on wsCur.
Also, the contents are cleared...so that line executes fine.
There is no Beep played after it dies.
I have a breakpoint on the Beep also, and it is never hit.因此,正如我在输入问题时通常发生的情况...我一直在尝试事情,通常会在尝试完全记录我的问题时最终找到我的答案。这次的结果还算不错……由于我找不到原因,上面的代码现在可以正常工作了……但是,我在VBA的其他部分仍然遇到了与上面的部分不一样的问题。我已经在这个项目上工作了一个星期左右,并且在今天之前的所有测试中,这段代码都已经起作用了……或者至少像通常预期的那样出错了。So, as what usually happens while I'm typing out a question...I keep trying things and usually end up finding my answer while trying to fully document my question.
Semi-decent results this time...for no reason that I can find, the code above is now working...however, I keep having the same issue in other parts of my VBA that aren't similar to the section above.
I've been working on this project for a week or so, and all testing prior to today, this code has worked...or at least errored out like would normally be expected.每次调试器停止时,没有错误,也没有警告。失败的线路甚至没有任何共同点。因此,我只能假设这对我的系统来说是环境。Each time the debugger stops, there is no error and no warning.
The lines that are failing don't even have anything in common.
So I'm left to assume that is it something environmental with my system.我已经搜索并搜索过Google,但没有答案。我希望这里的某个人以前曾遇到过此问题并可以解决,或者至少可以指出正确的方向。I've searched and Googled, and am left with no answers.
I'm hoping that some one here has had this issue before and resolved it, or can at least point me in the correct direction.我的代码编译没有错误。这是当前暂停的行:My code compiles without error.
This is the line that is currently halting:wsTemp.Delete
已删除临时工作表...然后暂停。Temp worksheet IS deleted...then halts. 编辑: ,所以我认为这只是一个损坏的Excel文件,因此需要执行Open&维修解决了几个小时。但是现在我遇到了同样的问题,在 Ok, so I thought this was just a corrupted Excel file, and doing an Open & Repair resolved it for a few hours.
But now I'm having the same issue where the debugger fails after
wsTemp.Delete
我打开了工具>选项>常规>遇到所有错误都中断,但仍然没有错误也没有警告...代码逐步停止I turned on Tools > Options > General > Break on ALL Errors and still I get no error and no warning...code step through just halts.只是要彻底...这里是到故障点为止的整个过程:Just to be thorough...here is the entire procedure up to the failure point:'Creates combined joblist from last and current month
Sub CreateCompareList(wsCur As Worksheet, wsLast As Worksheet, wsComp As Worksheet)
Dim wsTemp As Worksheet
Dim lLastRow As Long, lCurRow As Long, lLMRow As Long
Dim iCol As Integer, x As Integer
wsComp.Unprotect SheetPwd
lLastRow = wsComp.Cells(Rows.Count, 27).End(xlUp).Row
'Get the last row
If lLastRow = 9 Then
'No data on sheet - Don't ruin headers
Else
wsComp.Rows("10:" & lLastRow).ClearContents
'Clear that section of Job names and numbers
End If
Set wsTemp = Worksheets.Add
'Add a Temp Sheet to filter jobs
lCurRow = wsCur.[A10].End(xlDown).Row
'Get the last row
wsCur.Range("A10:B" & lCurRow).Copy
'Grab all jobs for the current month
wsTemp.[A1].PasteSpecial
'Paste job list from Current Month
Application.CutCopyMode = False
lLMRow = wsLast.[A10].End(xlDown).Row
'Get the last row
wsLast.Range("A10:B" & lLMRow).Copy
'Grab all jobs from the Last month
lLastRow = wsTemp.[A1].End(xlDown).Row
'Get the last row
wsTemp.Cells(lLastRow + 1, 1).PasteSpecial
'Paste jobs from last month below jobs from current month
Application.CutCopyMode = False
lLastRow = wsTemp.[A1].End(xlDown).Row
'Get new last row
'Filter out duplicates based on the JobNo
wsTemp.Range("$A$1:$B$" & lLastRow).RemoveDuplicates Columns:=2, Header:=xlNo
lLastRow = wsTemp.[A1].End(xlDown).Row
'Get new last row
wsTemp.Range("A1:B" & lLastRow).Copy
'Copy unique Jobs
wsComp.[A10].PasteSpecial
'Paste Unique Jobs to Compare sheet
'Clean up Temp sheet
'
Application.DisplayAlerts = False
wsTemp.Delete
我已经尝试过关闭和关闭DisplayAlerts,当警报打开时...我得到警报,表明工作表上可能有数据...我单击删除,工作表被删除...然后代码暂停。有时在上面的其他.ClearContents行上也会再次出现问题。I have tried it with the DisplayAlerts on and off, when the Alerts are on...I get the alert that there may be data on the sheet...I click delete, the sheet is deleted...and then code halts.
It occasionally has problems again on other .ClearContents lines like above.推荐答案关于这个问题的事后看来,得出的结论是实际上是损坏的Excel文件。幸运的是,我最近也进行了一次备份。但是,为了节省在该备份和损坏的版本之间进行编码所花费的时间,以下是我保存文件的步骤,以防万一其他人遇到我做的奇怪行为:Postmortem on this issue seems to lead to the conclusion that this was in fact a corrupted Excel file.
Luckily I had a fairly recent back up as well.
However, in order to save the time that had been spent coding between that backup and the corrupted version, here are the steps I took to save the file, in case anyone else encounters the strange behavior I did:关闭所有Excel窗口,并在不打开文件的情况下启动新实例。 使用Ctrl + O来搜索文件。 ..但是,不只是单击打开,而是单击向下箭头,然后选择打开&修复。 单击修复 另存为新副本*-已修复(正因为如此)。 Closed all Excel windows and started a fresh instance without opening a file.
Used Ctrl+O to search for the file...but instead of just clicking Open, click the down arrow and select Open & Repair.
Click Repair
Saved as a new copy *-Repaired (just because).
此后,文件按预期运行。 EOMONTH函数中的循环引用消失了,调试器按预期运行。我已经对所有代码进行了全面的测试,并且运行正常。After this, the file ran as expected.
The circular reference in the EOMONTH function went away and the debugger ran as expected.
I have run full testing on all code and it is working normally.我没有任何解释,说明它是如何损坏的,我很幸运。I have no explanation as to how it became corrupted, just lucky I guess.请参见 https://support.office.com/en-us/article/Repairing-a-corrupted-workbook-e5b49891-dde7-4796-b60a-49b0d2478a62 处理损坏时的其他选项Excel文件。See https://support.office.com/en-us/article/Repairing-a-corrupted-workbook-e5b49891-dde7-4796-b60a-49b0d2478a62 for other options when dealing with corrupted Excel files. 编辑::此问题再次出现,当前起作用的是强制执行Windows Update。该系统设置为自动,但是当我手动检查时,发现3个Office更新。安装这些文件后,我再次运行Windows Update,并为.Net框架找到了另一个更新...所以我也做到了...怀疑没有任何效果...但是...
This issue came back again and what currently has it working was forcing Windows Updates.
The system is set on Automatic, but when I manually went and checked, it found 3 Office updates.
After installing those, I ran Windows Update again and found another update for .Net framework...so I did that as well...doubt that had any effect...but...所以...在使用Excel的Open&之后修复,应用更新并重新启动几次,然后打开Break on all errors ...我的代码终于可以继续正常工作了。So...after using Excel's Open & Repair, applying updates and restarting a couple of times, turning on Break on all errors...my code is finally working again all the way through.这篇关于Excel VBA调试器停止运行,没有错误或警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!}

我要回帖

更多关于 需要vba支持,请安装vba后重试 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信