Daruki
Daruki

Reputation: 491

Add yes/no to objshell.popup in VBA

Below is my attempt at adding yes/no options to my objshell.popup, getting a type mismatch error, probably doing something wrong...

got it from this website: http://www.informit.com/articles/article.aspx?p=1170490&seqNum=5

  Public Sub ShowTable()

Dim myData
Dim myStr As String
Dim x As Integer
Dim myRange As Range
Dim lastrow As Long
Dim nsecond As Long
Dim ws As Worksheet


Call reviewME

UserForm1.Show

Set ws = Worksheets("New Lookups")
lastrow = ws.Cells(Rows.Count, 262).End(xlUp).Row
Set myRange = ws.Range(ws.Cells(2, 262), ws.Cells(lastrow, 262))

myData = myRange.Value

For x = 1 To UBound(myData, 1)
    myStr = myStr & myData(x, 1) & vbTab & vbCrLf
Next x

'myStr = myStr & vbNewLine & "Proceed with change requests?"


inttype = vbYesNo + vbQuestion + vbDefaultButton2

Set objshell = CreateObject("Wscript.Shell")
strtitle = "Review your entries"
nsecond = 1
intresult = objshell.popup(myStr, nsecond, strtitle, inttype)

Select Case intresult
    Case vbYes
        MsgBox "hi"
    Case vbNo
        MsgBox "no"
End Select

Upvotes: 0

Views: 991

Answers (1)

Patrick Wynne
Patrick Wynne

Reputation: 2124

It's because the signature for the Popup method is actually:

WshShell.Popup(strText, [nSecondsToWait], [strTitle], [intType])

and you are forgetting the nSecondsToWait parameter.

nSecondsToWait may be an optional param (as indicated by the brackets around the param name) but if you aren't going to include it then you need to leave an empty slot for it:

intresult = objshell.popup(myStr, , strtitle, inttype)

The type mismatch error is because the second param should be an integer (nSecondsToWait) but you are giving it a string ("Review your entries").

Upvotes: 2

Related Questions