如何解决“运行时错误424:需要对象”? [英] How to resolve "run time error 424: object required"?

查看:1269
本文介绍了如何解决“运行时错误424:需要对象”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试运行该程序时,它会显示运行时错误。



我尝试了什么:



  Sub  Macro1()
对于 i = 1 255
工作表( sheet1)。选择
工作表( sheet1)。激活
mystr = http://www.medifee.com/dc/243-rushabh-diagnostic-centre/
mystr = Cells(i, 1
Worksheets.Add(After:= Worksheets(Worksheet.Count))。Name = i
ActiveWorkbook.Worksheets.Add
使用 ActiveSheet.QueryTables.Add(连接:= _
mystr,Destinatio n:= _
范围( $ A $ 1))
。 Name = 243-rushabh-diagnostic-center
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
。 RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:= False
End 使用



下一步
结束 Sub

解决方案

< blockquote> A


1))
.Name = 243-rushabh-diagnostic-center
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = 错误
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSing leBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:= False
End 使用



下一步
结束 Sub


我们无法分辨 - 我们无法访问你的数据检查代码并为你工作。

所以,它取决于你。

在函数的第一行放一个断点,并通过调试器运行您的代码。然后查看您的代码,并查看您的数据并找出手动应该发生的事情。然后单步执行每一行检查您预期发生的情况正是如此。如果不是,那就是当你遇到问题时,你可以回溯(或者再次运行并仔细观察)以找出原因。


对不起,但我们不能为你做到这一点 - 时间让你学习一种新的(非常非常有用的)技能:调试!



看看这些,它们可以帮助您入门:

MS Excel 2013:VBA调试简介 [ ^ ]

在VBA中逐步执行代码的方法 [ ^ ]


when i try to run the program it shows the run time error.

What I have tried:

Sub Macro1()
For i = 1 To 255
Worksheets("sheet1").Select
Worksheets("sheet1").Activate
mystr = "http://www.medifee.com/dc/243-rushabh-diagnostic-centre/"
mystr = Cells(i, 1)
Worksheets.Add(After:=Worksheets(Worksheet.Count)).Name = i
ActiveWorkbook.Worksheets.Add
    With ActiveSheet.QueryTables.Add(Connection:= _
        mystr, Destination:= _
        Range("$A$1"))
        .Name = "243-rushabh-diagnostic-center"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlAllTables
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With



Next
End Sub

解决方案

A


1")) .Name = "243-rushabh-diagnostic-center" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .WebSelectionType = xlAllTables .WebFormatting = xlWebFormattingNone .WebPreFormattedTextToColumns = True .WebConsecutiveDelimitersAsOne = True .WebSingleBlockTextImport = False .WebDisableDateRecognition = False .WebDisableRedirections = False .Refresh BackgroundQuery:=False End With Next End Sub


We can't tell - we don't have access to your data to check the code and work it out for you.
So, its going to be up to you.
Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!

Have a look at these, they may help you get started:
MS Excel 2013: VBA Debugging Introduction[^]
Ways to Step Through Code in VBA[^]


这篇关于如何解决“运行时错误424:需要对象”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆