我有一个MS Word文档,它生成一个Excel,其中包含Word文档中的表格中的数据。 Word表格的Excel版本旨在成为一个清单。因此,我试图为生成的Excel添加功能,以使其更加有用。我尝试添加条件格式(如果行标记为完成,则使行成为绿色)和验证(因此“已完成”列的下拉列表为“是”或“否”)。我可以让这两个工作在Excel中,但不能从Word中获取VBA以将功能添加到生成的Excel中。Excel Validation.Add无法从MS Word VBA工作
在这两种情况下.Add方法似乎导致问题。我试图2个语法做到这一点:
With objNewExcel.Sheets(1).Range("e5").Validation
.Add Type:=xlValidateWholeNumber, _
AlertStyle:= xlValidAlertStop, _
Operator:=xlBetween, _
Formula1:="5", _
Formula2:="10"
.InputTitle = "Integers"
.ErrorTitle = "Integers"
.InputMessage = "Enter an integer from five to ten"
.ErrorMessage = "You must enter a number from five to ten"
End With
返回错误“练成运行时错误‘1004’的应用程序定义或对象定义的误差”,这是没有用的
和
objNewExcel.Sheets(1).Range("e5").Validation.Add(xlValidateWholeNumber, xlValidAlertStop, xlBetween, "5", "10")
返回错误“预期:=”。当我将验证设置为var时,它会给我一个类型错误匹配错误。我将var作为对象进行了DIM。
我不能从MS Word VBA中工作。有谁知道如何引用Word VBA中的Excel .Add方法?