VBA-四行(你能用简单的英语解释一下吗?)

时间:2015-11-30 04:45:15

标签: vba excel-vba excel

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)

If Not Intersect(Target, Range(pRngBoardSize)) Is Nothing Then
'if the target is within the given range this part of the code gets activated
Cancel = True

End If

End Sub

我提出了自己的解释,但你能确定它是对的,你能告诉我为什么我们使用cancel = true吗? 谢谢!

1 个答案:

答案 0 :(得分:2)

当我们右键单击工作表时,我们得到的是右键单击弹出菜单。

因此,如果您设置Worksheet_BeforeRightClick,则在尝试显示时取消弹出窗口,实际上右键单击的用户将看不到弹出窗口。

sub的名称全部为Cancel,它是在正确执行RightClick操作之前的那一刻运行的例程,因此如果你仍然可以提供命令Target希望它不要继续。

您的代码似乎做的是,如果pRngBoardSize单元格与预定义区域Target不重叠,则右键单击<form id="addnew"> <input type="text" class="id"> <input type="text" class="content"> <input type="submit" value="Add"> </form> <script> jQuery(function($) { $('#form_addjts').submit(function(){ writeToFile({ id: $(this).find('.id').val(), content: $(this).find('.content').val() }); return false; }); function writeToFile(data){ var fso = new ActiveXObject("Scripting.FileSystemObject"); var fh = fso.OpenTextFile("D:\\data.txt", 8); fh.WriteLine(data.id + ',' + data.content); fh.Close(); } }); </script> 单元格不会弹出弹出窗口菜单。