-
Jul 10th, 2013, 10:06 AM
#1
Thread Starter
New Member
YesNo Message box gives "Run-time error 424: Object required" when click "No" button.
Hello all,
I am completely new to visual basic. I am trying to get a message box to pop up whenever an employee creates a new Word document from a template. The template has fields in it and I want the message box to have a hyperlink to a page on our intranet that gives instructions on how to properly edit the fields. Most of our employees do not know how. I have found that you cannot have a hyperlink in a message box, but you can use Yes/No buttons where the Yes button sends you to a website. I found some code online for this, but it is from 2007, an does not have any recent posts, so I highly doubt the original author of the code would post a response.
I have placed the following code, I found, in the Project Explorer, under "Microsoft Word Objects", in "ThisDocument":
Code:
Private Sub Document_New()
Set objShell = CreateObject("Wscript.Shell")
intMessage = MsgBox("Test Message", _
vbYesNo, "Instructions for Proper Field Editing")
If intMessage = vbYes Then
objShell.Run ("http://www.microsoft.com")
Else
Wscript.Quit
End If
End Sub
When I open Word and click on New, then on My Templates, then double-click the .dotm file that has the code, I get the message box (1st image below) just fine, and when I click "Yes" it takes me to the website listed in the code, but if I click "No" I get a Run-time error '424': Object required message (2nd image below).
Any clue what I have wrong?
Thanks for any help,
Jake
-
Jul 10th, 2013, 10:15 AM
#2
Thread Starter
New Member
Re: YesNo Message box gives "Run-time error 424: Object required" when click "No" but
I forgot to mention, when I click the Debug button, it highlights the "Wscript.Quit" line.
Thanks for any help,
Jake
-
Jul 10th, 2013, 10:45 AM
#3
Re: YesNo Message box gives "Run-time error 424: Object required" when click "No" but
I would think it would something more like "objShell.close" or "set objShell = nothing" that you'd want in the "Else" clause
-
Jul 10th, 2013, 10:47 AM
#4
Re: YesNo Message box gives "Run-time error 424: Object required" when click "No" but
and I'm sure if you inspected it, you'd find that "Wscript" is nothing... and therefore you cannot call a method of an object that doesn't exist... it's about as effective as an air guitar at a rock concert... You're calling Quit on the wrong thing.
-tg
-
Jul 10th, 2013, 11:10 AM
#5
Re: YesNo Message box gives "Run-time error 424: Object required" when click "No" but
Tg, what's wrong with an air guitar at a rock concert? *biggrin* *headbang*
ok, nothing to do with the thread, but what was to be said has been said *g*
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Jul 10th, 2013, 11:34 AM
#6
Re: YesNo Message box gives "Run-time error 424: Object required" when click "No" but
:P nothing in inherently wrong with it... unless it's the BAND that's using it...
-tg
-
Jul 11th, 2013, 11:17 AM
#7
Thread Starter
New Member
Re: YesNo Message box gives "Run-time error 424: Object required" when click "No" but
I tried changing the Else statement to "Else objShell.close" and "Else objShell = nothing" but they didn't work.
I do some code work in AutoLISP for AutoCAD and I know that the "Else" part of an "IF" function is optional, so I got it working by just taking out the Else statement (Else Wscript.Quit).
Thanks for the help everyone, I appreciate it.
Jake
-
Jul 11th, 2013, 11:24 AM
#8
Re: YesNo Message box gives "Run-time error 424: Object required" when click "No" but
And again a prime example of finding a crude solution without understanding the underlying problem.
he lucks out that objshell is declared in the scope of the open-event and destroys itself with leaving the procedure
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Jul 11th, 2013, 11:28 AM
#9
Thread Starter
New Member
Re: YesNo Message box gives "Run-time error 424: Object required" when click "No" but
Zvoni,
If you have a better solution that is the proper way of ending the IF function, let me know. As I stated, I am completely new to visual basic, so yeah, I don't understand the underlying problem. If you know the correct way to end the IF function, I will happily implement it.
Jake
-
Jul 11th, 2013, 11:36 AM
#10
Re: YesNo Message box gives "Run-time error 424: Object required" when click "No" but
Object-variables, in your case "objshell", are always SET to something, even if it's "Nothing".......
I think you'll get my drift if you compare it to your attempt.
i apologize, since i missed the "i'm new to vb". Normaly i skip introductory text to what person is how experienced in whatever, and jump directly on the problem-description and/or code-snippets
EDIT: out of curiosity: did you try objshell.quit?
i admit that i have no clue about wscript (or script-objects in general) since i never used them in my life
Last edited by Zvoni; Jul 11th, 2013 at 11:52 AM.
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Jul 11th, 2013, 01:45 PM
#11
Addicted Member
Re: YesNo Message box gives "Run-time error 424: Object required" when click "No" but
A better solution might be to only create the shell object if it's needed:
Code:
Private Sub Document_New()
intMessage = MsgBox("Test Message", _
vbYesNo, "Instructions for Proper Field Editing")
If intMessage = vbYes Then
Set objShell = CreateObject("Wscript.Shell")
objShell.Run ("http://www.microsoft.com")
End If
End Sub
-
Jul 11th, 2013, 04:25 PM
#12
Re: YesNo Message box gives "Run-time error 424: Object required" when click "No" but
as objshell is just left to go out of scope, in case of yes answer, i do not see it would need to be quit in the other case, else better it should be quit and set to nothing in both cases (outside the if statement)
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jul 11th, 2013, 10:18 PM
#13
Re: YesNo Message box gives "Run-time error 424: Object required" when click "No" but
Maybe a stupid question: in this particular case, why even use a latebound shell-object? Why not use the plain old shell-function?
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Jul 12th, 2013, 05:27 AM
#14
Re: YesNo Message box gives "Run-time error 424: Object required" when click "No" but
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jun 22nd, 2017, 04:37 AM
#15
New Member
Re: YesNo Message box gives "Run-time error 424: Object required" when click "No" but
Hi I am facing 424 object required error. below is my code
Private Sub CommandButton21_Click()
UserCredentiald.Username.Value = ""
UserCredentiald.Password.Value = ""
UserCredentiald.Domain.Value = ""
UserCredentiald.Project.Value = ""
Module1.Rectangle1_Click
Username = UserCredentiald.Username.Value
Password = UserCredentiald.Password.Value
Domain = UserCredentiald.Domain.Value
Project = UserCredentiald.Project.Value
Start_Row = 2
Result_Row = 2
Set Sh1 = Sheets("Sheet1")
If Username <> "" And Password <> "" And Domain <> "" And Project <> "" Then
'Do nothing
Else
MsgBox "Please enter the cresentials in the fields"
End If
While (Sh1.Cells(Start_Row, 1) <> "")
StatusFlag = 0
Flag_Value2 = 0
On Error Resume Next
Set QCConnection = CreateObject("TDApiOle80.TDConnection")
If QCConnection.Connected <> "True" Then
QCConnection.InitConnectionEx "http://qcalm.kp.org/qcbin"
QCConnection.Login Username, Password
QCConnection.Connect Domain, Project
End If
On Error GoTo 0
testplanpath = Sh1.Cells(Start_Row, 2)
testLabPath = Sh1.Cells(Start_Row, 3)
testSetName = Sh1.Cells(Start_Row, 4)
testType = Sh1.Cells(Start_Row, 5)
testcasename = Sh1.Cells(Start_Row, 6)
''''''''''The code to traverse upto last node folder
Set QCTreeManager = QCConnection.TreeManager
Set obj1 = QCTreeManager.NodebyPath(testplanpath)
If obj1.Count > 0 Then
For i = 1 To obj1.Count
Parent_path1 = obj1.Child(i).Path
'MsgBox Parent_path1
Set parenet_obj2 = QCTreeManager.NodebyPath(Parent_path1)
'MsgBox parenet_obj2.Count
If parenet_obj2.Count > 0 Then
For j = 1 To parenet_obj2.Count
Final_Parentpath = parenet_obj2.Child(j).Path
'MsgBox Final_Parentpath
Flag_Value2 = Find_Lstnode(Final_Parentpath, testcasename, testLabPath, testSetName)
If Flag_Value2 = 1 Then
Sh1.Cells(Start_Row, 7).Value = "Success"
Exit For
End If
Next
End If
If Flag_Value2 = 1 Then
Exit For
End If
Next
Else
Lnode1 = obj1.Path
Flag_Value = Find_Expectedpath(Lnode1, testcasename, testLabPath, testSetName)
If Flag_Value > 0 Then
Sh1.Cells(Start_Row, 7).Value = "Success"
Else
Sh1.Cells(Start_Row, 7).Value = "Test Case Not Found"
End If
End If
Set QCConnection = CreateObject("TDApiOle80.TDConnection")
' MsgBox QCConnection.Connected
If QCConnection.Connected Then
QCConnection.Disconnect
QCConnection.Logout
QCConnection.ReleaseConnection
End If
If Flag_Value2 = "" Then
Sh1.Cells(Start_Row, 7).Value = "Test Case Not Found"
End If
Start_Row = Start_Row + 1
Wend
' MsgBox "Completed"
End Sub
Function Find_Lstnode(Final_Parentpath, testcasename, testLabPath, testSetName)
Flag_Value = 0
Username = UserCredentiald.Username.Value
Password = UserCredentiald.Password.Value
Domain = UserCredentiald.Domain.Value
Project = UserCredentiald.Project.Value
Set QCConnection = CreateObject("TDApiOle80.TDConnection")
If QCConnection.Connected <> "True" Then
QCConnection.InitConnectionEx "http://qcalm.kp.org/qcbin"
QCConnection.Login Username, Password
QCConnection.Connect Domain, Project
End If
Set QCTreeManager = QCConnection.TreeManager
Set lastnode_obj = QCTreeManager.NodebyPath(Final_Parentpath)
If lastnode_obj.Count = 0 Then
Flag_Value = Find_Expectedpath(Final_Parentpath, testcasename, testLabPath, testSetName)
If Flag_Value = 1 Then
Find_Lstnode = Flag_Value
Exit Function
End If
Else
For l = 1 To lastnode_obj.Count
Lnode = lastnode_obj.Child(l).Path
'MsgBox Lnode
Set lastnode_obj1 = QCTreeManager.NodebyPath(Lnode)
'MsgBox lastnode_obj1.Count
If lastnode_obj1.Count = 0 Then
Flag_Value = Find_Expectedpath(Lnode, testcasename, testLabPath, testSetName)
If Flag_Value = 1 Then
Find_Lstnode = Flag_Value
Exit Function
End If
Else
For m = 1 To lastnode_obj1.Count
Lnode1 = lastnode_obj1.Child(m).Path
'MsgBox Lnode1
Set QCTreeManager = QCConnection.TreeManager
Set lastnode_obj2 = QCTreeManager.NodebyPath(Lnode1)
'MsgBox lastnode_obj2.Count
If lastnode_obj2.Count = 0 Then
Flag_Value = Find_Expectedpath(Lnode1, testcasename, testLabPath, testSetName)
If Flag_Value = 1 Then
Find_Lstnode = Flag_Value
Exit Function
End If
Else
For k = 1 To lastnode_obj2.Count
Lnode2 = lastnode_obj2.Child(k).Path
'MsgBox Lnode2
Set QCTreeManager = QCConnection.TreeManager
Set lastnode_obj3 = QCTreeManager.NodebyPath(Lnode2)
'MsgBox lastnode_obj3.Count
If lastnode_obj3.Count = 0 Then
Flag_Value = Find_Expectedpath(Lnode2, testcasename, testLabPath, testSetName)
If Flag_Value = 1 Then
Find_Lstnode = Flag_Value
Exit Function
End If
End If
Next
End If
Next
End If
Next
End If
End Function
Function Find_Expectedpath(Test_path, testcasename, testLabPath, testSetName)
Flag_Value1 = 0
Username = UserCredentiald.Username.Value
Password = UserCredentiald.Password.Value
Domain = UserCredentiald.Domain.Value
Project = UserCredentiald.Project.Value
Set QCConnection = CreateObject("TDApiOle80.TDConnection")
If QCConnection.Connected <> "True" Then
QCConnection.InitConnectionEx "http://qcalm.kp.org/qcbin"
QCConnection.Login Username, Password
QCConnection.Connect Domain, Project
End If
Set QCTreeManager = QCConnection.TreeManager
Set lastnode_obj = QCTreeManager.NodebyPath(Test_path)
Set TestFact = lastnode_obj.TestFactory
Set TestsList = TestFact.NewList("")
For Each tests In TestsList
'MsgBox tests.Name
If tests.Name = testcasename Then
'MsgBox tests.Name
'MsgBox Test_path
Flag_Value1 = Testlab_Code(Test_path, testLabPath, testcasename, testSetName)
If Flag_Value1 = 1 Then
Find_Expectedpath = Flag_Value1
Exit Function
End If
End If
Next
End Function
'''''''''''''''''''Final code
Function Testlab_Code(Final_testplanpath, testLabPath, testcasename, testSetName)
bFlag = 0
Username = UserCredentiald.Username.Value
Password = UserCredentiald.Password.Value
Domain = UserCredentiald.Domain.Value
Project = UserCredentiald.Project.Value
Set QCConnection = CreateObject("TDApiOle80.TDConnection")
If QCConnection.Connected <> "True" Then
QCConnection.InitConnectionEx "http://qcalm.kp.org/qcbin"
QCConnection.Login Username, Password
QCConnection.Connect Domain, Project
End If
Set QCTreeManager = QCConnection.TreeManager
Set TestNode = QCTreeManager.NodebyPath(Final_testplanpath)
Set TestFact = TestNode.TestFactory
Set TestsList = TestFact.NewList("")
' For Each tests In TestsList
' MsgBox tests.Name
' MsgBox tests.ID
' Next
'''''''''''''''''''''''''''*****************The code for add test set in test lab
Set QCTSTreeManager = QCConnection.TestSetTreeManager
Set TreeNode = QCTSTreeManager.NodebyPath(testLabPath)
Set TestSetFact = TreeNode.TestSetFactory
Set obj1 = TestSetFact.NewList("")
For Each obj2 In obj1
If obj2.Name = testSetName Then
Set objtestinstance = obj2.TSTestFactory
For Each tests In TestsList
TestName_Temp = tests.Name
If testcasename = TestName_Temp Then
'Set lablist = TSTestFactory.NewList(obj2.ID)
Set obj3 = objtestinstance.AddItem(tests.ID)
obj3.Status = "No Run"
obj3.Post
bFlag = 1
Testlab_Code = bFlag
Exit For
End If
Next
End If
Next
'Set NewTestSet = TestSetFact.TestSet ' Creates new testset
' NewTestSet.Name = testSetName
' NewTestSet.field("CY_COMMENT") = testSetName
' NewTestSet.Status = "Open"
' NewTestSet.Post
' Set TSTestFactory = NewTestSet.TSTestFactory
' For Each tests In TestsList
' If tests.Field("TS_TYPE") = testType Then
' TSTestFactory.AddItem (tests)
' End If
' Next
End Function
Private Sub CommandButton22_Click()
Username.Value = ""
Password.Value = ""
Domain.Value = ""
Project.Value = ""
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|