运行时错误1004:应用程序定义或对象定义错误。 [英] Run time error 1004: Application defined or object defined error.
本文介绍了运行时错误1004:应用程序定义或对象定义错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我创建的宏的代码,并为其分配了一个控制按钮,之前我遇到了运行时错误同样也没有保护我的工作表。工作正常,但现在我又得到了同样的错误。
有人可以指导我,我是VBA的新人。
提前谢谢你:)
Hi,
Here is the code for the macro I created and assigned it a control button,I was getting run time error before as well and unprotected my worksheet.It worked fine but now again I am getting the same error.
Can someone please guide me i M NEW TO VBA.
Thankyou in advance :)
Sub mysecond()
'
' mysecond Macro
'
' Keyboard Shortcut: Ctrl+Shift+L
'
Range("W3").Select
ActiveCell.FormulaR1C1 = _
"=IF(AND(RC[-1]>0,RC[-2]=""fully on""),volteq(RC[-1]),IF(AND(RC[-1]>0,RC[-2]=""fully off""),0,IF(AND(RC[-1]<0,RC[-2]=""fully on""),dvolteq(RC[-1]),IF(AND(RC[-1]<0,RC[-2]=""fully off""),0))))"
Range("W1").Select
ActiveCell.FormulaR1C1 = "switch voltage(V)"
Range("X2").Select
Columns("W:W").ColumnWidth = 14.86
Range("W3").Select
Selection.Copy
Range("U3").Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, 2).Range("A1").Select
Range(Selection, Selection.End(xlUp)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveWindow.SmallScroll ToRight:=3
ActiveWindow.ScrollRow = 20209
ActiveWindow.ScrollRow = 15718
ActiveWindow.ScrollRow = 11227
ActiveWindow.ScrollRow = 6737
ActiveWindow.ScrollRow = 4492
ActiveWindow.ScrollRow = 1
Range("X3").Select
ActiveCell.FormulaR1C1Local = _
"=IF(AND(RC[-3]=""fully on"",OR(AND(RC[-2]>0,RC[-1]>0),AND(RC[-2]<0,RC[-1]<0))),(RC[-2]*RC[-1]*1000),IF(AND(RC[-3]=""fully on"",OR(AND(RC[-2]>0,RC[-1]<0),AND(RC[-2]<0,RC[-1]>0))),(RC[-2]*RC[-1]*-1000),IF(AND(RC[-2]=0,OR(RC[-3]=""fully on"",RC[-3]=""fully off"",RC[-3]=""T on"",RC[-3]=""T off"")),0,IF(AND(RC[-3]=""fully off"",RC[-2]>0),(RC[-2]*RC[-1]*1000),IF(AND(RC[-3" & _
"y off"",RC[-2]<0,RC[-1]<0),(RC[-2]*RC[-1]*1000),IF(AND(RC[-3]=""fully off"",RC[-2]<0,RC[-1]>0),(RC[-2]*RC[-1]*-1000),IF(AND(OR(RC[-3]=""T on"",RC[-3]=""T off""),RC[-2]>0),transeq(RC[-2]),IF(AND(OR(RC[-3]=""T on"",RC[-3]=""T off""),RC[-2]<0),(-1*transeq(RC[-2]))))))))))"
Range("X3").Select
Selection.Copy
Range("U3").Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, 3).Range("A1").Select
Range(Selection, Selection.End(xlUp)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveWindow.ScrollRow = 20209
ActiveWindow.ScrollRow = 17963
ActiveWindow.ScrollRow = 15718
ActiveWindow.ScrollRow = 13473
ActiveWindow.ScrollRow = 6737
ActiveWindow.ScrollRow = 2246
ActiveWindow.ScrollRow = 1
Range("X1").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
ActiveCell.FormulaR1C1 = "power losses in mJ/s"
Range("X2").Select
Columns("X:X").ColumnWidth = 14.71
Columns("X:X").ColumnWidth = 17.43
Columns("X:X").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("Y1").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
ActiveCell.FormulaR1C1 = "energy (mJ)"
Range("Y3").Select
ActiveCell.FormulaR1C1 = "=RC[-1]*RC[-10]"
Range("Y3").Select
Selection.Copy
Range("O3").Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, 10).Range("A1").Select
Range(Selection, Selection.End(xlUp)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveWindow.ScrollRow = 20209
ActiveWindow.ScrollRow = 13473
ActiveWindow.ScrollRow = 11227
ActiveWindow.ScrollRow = 8982
ActiveWindow.ScrollRow = 4492
ActiveWindow.ScrollRow = 2246
ActiveWindow.ScrollRow = 1
Range("Y1").Select
Columns("Y:Y").ColumnWidth = 11.57
Columns("X:X").ColumnWidth = 21
Range("U8").Select
End Sub
推荐答案
建议:使用调试器运行程序,滥用调试器。
首先找出问题所在。
建议:尝试制作一个出现错误的较短程序,帮助他们弄清楚出了什么问题。
Advice: run you program with the debugger, abuse the debugger.
First of all find where the problem is.
Advice: Try to make a shorter program that exhibit the error, it help helpers to figure out what goes wrong.
这篇关于运行时错误1004:应用程序定义或对象定义错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文