我正在使用Excel,其中某些字段允许用户输入,其他单元格将受到保护.我使用过工具保护表,但是在执行此操作后,我无法更改VBA脚本中的值.我需要限制工作表以停止用户输入,同时允许VBA代码根据某些计算更改单元格值.
我有以下代码
For x = LBound(arr) To UBound(arr)
sname = arr(x)
If instr(sname, "Configuration item") Then
'**(here i want to go to next x in loop and not complete the code below)**
'// other code to copy past and do various stuff
Next x
Run Code Online (Sandbox Code Playgroud)
所以我认为我可以简单地使用该语句Then Next x,但这会给出"no for statement声明"错误.
那么我可以在If instr(sname, "Configuration item") Then它进入x的下一个值之后放入什么呢?
所以这是错误:在64 位VBA 主机(例如 Access 365 64 位或 Excel 2016 64 位)中创建一个类模块SomeClass:
' this needs to be here to trigger the bug:
Private Sub Class_Terminate()
End Sub
Run Code Online (Sandbox Code Playgroud)
然后是一些模块Test:
Function ReturnFalse(o As Object) As Boolean
ReturnFalse = False
End Function
Sub Test()
Debug.Print ReturnFalse(New SomeClass)
If ReturnFalse(New SomeClass) Then
Debug.Print True
Else
Debug.Print False
End If
End Sub
Run Code Online (Sandbox Code Playgroud)
现在,如果您使用的是32 位VBA 主机并在即时窗口中运行“测试” ,则会显示预期结果:
False
False
Run Code Online (Sandbox Code Playgroud)
但是,如果您使用的是64 位VBA 主机,则会出现:
False
True
Run Code Online (Sandbox Code Playgroud)
除了,当您删除或重命名Class_Terminate()sub …
我想检查空数组.Google给了我各种解决方案,但没有任何效果 也许我没有正确应用它们.
Function GetBoiler(ByVal sFile As String) As String
'Email Signature
Dim fso As Object
Dim ts As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
GetBoiler = ts.ReadAll
ts.Close
End Function
Dim FileNamesList As Variant, i As Integer
' activate the desired startfolder for the filesearch
FileNamesList = CreateFileList("*.*", False) ' Returns File names
' performs the filesearch, includes any subfolders
' present the result
' If there are Signatures then populate SigString
Range("A:A").ClearContents
For i = …Run Code Online (Sandbox Code Playgroud) 我已经和VBA合作了很长一段时间了,但我对错误处理仍然不太了解.
一篇好文章是CPearson.com的文章
但是我仍然想知道我以前使用ErrorHandling的方式是否完全错误: 第1块
On Error Goto ErrCatcher
If UBound(.sortedDates) > 0 Then
// Code
Else
ErrCatcher:
// Code
End If
Run Code Online (Sandbox Code Playgroud)
if子句,因为如果它是真的,它将被执行,如果它失败,Goto将进入Else-part,因为数组的Ubound不应该为零或更少,没有Error,这种方法工作得很好至今.
如果我理解正确,它应该是这样的: 第2块
On Error Goto ErrCatcher
If Ubound(.sortedDates) > 0 Then
// Code
End If
Goto hereX
ErrCatcher:
//Code
Resume / Resume Next / Resume hereX
hereX:
Run Code Online (Sandbox Code Playgroud)
或者甚至像这样: 第3座
On Error Goto ErrCatcher
If Ubound(.sortedDates) > 0 Then
// Code
End If
ErrCatcher:
If Err.Number <> 0 then
//Code
End If
Run Code Online (Sandbox Code Playgroud)
我看到的最常见的方式是,一个错误"Catcher"位于sub的末尾,Sub实际上以"Exit Sub"结束,但是如果Sub是相当的话,它不会有点混乱如果你反之亦然阅读代码?
第4座
以下代码的来源: CPearson.com …
在这部分代码中,Excel总是提示:"文件已存在,您要覆盖吗?"
Application.DisplayAlerts = False
Set xls = CreateObject("Excel.Application")
Set wb = xls.Workbooks.Add
fullFilePath = importFolderPath & "\" & "A.xlsx"
wb.SaveAs fullFilePath, AccessMode:=xlExclusive, ConflictResolution:=True
wb.Close(True)
Run Code Online (Sandbox Code Playgroud)
db.SaveAs如果有的话,为什么总是提示我覆盖现有文件DisplayAlerts = False?
提前致谢!
我有excel表格的数据,我想得到Levenshtein他们之间的距离.我已经尝试导出为文本,从脚本(php)读入,运行Levenshtein(计算Levenshtein距离),再次将其保存为excel.
但我正在寻找一种以编程方式计算VBA中的Levenshtein距离的方法.我该怎么做呢?
可以从一个Module到另一个调用一个函数吗?
我有以下代码:
Sub MAIN()
Call IDLE
End Sub
Run Code Online (Sandbox Code Playgroud)
MAIN 位于 Module1IDLE位于Module2并定义为:Sub IDLE()