【发布时间】:2013-03-14 16:52:57
【问题描述】:
我创建了一个宏来从我的 excel 文件中的空行中删除所有边框。这是mig代码:
Sub RemoveRows()
'
' RemoveRows Macro
'
'
Range("A8").Select
Dim checkval
Dim RowAmount
RowAmount = 93
Do
checkval = ActiveCell.Value
If (checkval = "" Or checkval = Null) Then
ActiveCell.EntireRow.Delete
Else
ActiveCell.Offset(1, 0).Select
End If
RowAmount = RowAmount - 1
Loop While RowAmount > 0
End Sub
运行宏的方法:
public void RemoveRows_Macro(string fileName)
{
Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
xlWorkBook = xlApp.Workbooks.Open(fileName);
xlApp.DisplayAlerts = true;
//Run the macro
xlApp.Run("RemoveRows", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
xlWorkBook.Save();
xlWorkBook.Close(false);
xlApp.Quit();
releaseObject(xlApp);
releaseObject(xlWorkBook);
}
我的问题是我可以从我的 C# 应用程序运行此宏而不会出现此错误,但是当其他人使用我的 C# 应用程序时会收到此错误:Run-time error '13': Type Mismatch
我做错了什么?
【问题讨论】:
-
请告诉我们您是如何运行宏的?另外,错误发生在哪个地方?
-
此代码直接从 Excel 2010 中的 vba 按预期运行。
-
当我运行宏时,它也可以在我的计算机上完美运行。但是当宏在某些(不是所有)机器上运行时,就会出现这个错误。此行发生错误:If (checkval = "" Or checkval = Null) Then
-
检查单元格中的
Null是没有意义的,因为单元格不能是Null。他们可以是Empty。请注意,所有Empty单元格也是= "",但并非所有= ""单元格都是Empty
标签: .net excel excel-2010 vba