在VBA中向objshell.popup添加yes / no

时间:2017-01-17 20:54:56

标签: vba excel-vba excel

下面是我尝试在我的objshell.popup中添加yes / no选项,导致类型不匹配错误,可能做错了...

从这个网站获得: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

1 个答案:

答案 0 :(得分:2)

这是因为Popup方法的签名实际上是:

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

您忘记了nSecondsToWait参数。

nSecondsToWait可能是一个可选的参数(如参数名称旁边的括号所示)但是如果您不打算包含它,那么您需要留下一个空插槽:

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

类型不匹配错误是因为第二个参数应该是一个整数(nSecondsToWait),但是你给它一个字符串("Review your entries")。