Board logo

標題: [發問] 無法產生inputbox [打印本頁]

作者: henry860608    時間: 2020-8-6 00:19     標題: 無法產生inputbox

本帖最後由 henry860608 於 2020-8-6 00:32 編輯

1.檔案中有4個工作表,分別為工作表1~4,工作表3有程式碼(使用者須輸入密碼),但是從工作表1切換過去到工作表3,程式碼先檢查權限,不足則輸入密碼。但是密碼的視窗無法產生,而會使檔案當掉,請問有方法解決嗎?
2.附件與代碼如下。
  1. Public Function InputBoxEr(Sht As Integer, iRow As Integer, Optional AddStr) As String

  2.     Dim Prompt As String, Title As String, Default As String, HelpFile As String, Context As String, Hack As String, tmp As String
  3.     Dim Xpos As Double, Ypos As Double
  4.     Dim i As Integer, Count As Integer, RoleSet As Integer, LmtCnt As Integer, Delay As Integer, min As Integer, sec As Integer
  5.     Dim StartRecTime As Date, EndtRecTime As Date, StartTime As Date, EndTime As Date
  6.    
  7.    
  8.    

  9.     With Sheets(Sht)
  10.         
  11.         Prompt = .Cells(iRow, 1)
  12.         Title = .Cells(iRow, 2)
  13.         Default = .Cells(iRow, 3)
  14.         Xpos = .Cells(iRow, 4)
  15.         Ypos = .Cells(iRow, 5)
  16.         HelpFile = .Cells(iRow, 6)
  17.         Context = .Cells(iRow, 7)
  18.         Hack = .Cells(iRow, 8)
  19.         RoleSet = .Cells(iRow, 10)
  20.         LmtCnt = .Cells(iRow, 11)
  21.         Delay = .Cells(iRow, 12)
  22.         StartRecTime = .Cells(iRow, 13)
  23.         EndtRecTime = .Cells(iRow, 14)
  24.         StartTime = .Cells(iRow, 15)
  25.         EndTime = .Cells(iRow, 16)
  26.         Count = .Cells(iRow, 8)

  27.         If RoleSet >= 0 Then
  28.         Else
  29.             MsgBox "錯誤!": Exit Function
  30.         End If
  31.         If (LmtCnt > 0 And Delay > 0) Or (LmtCnt = 0 And Delay = 0) Then
  32.         Else
  33.             MsgBox "錯誤!": Exit Function
  34.         End If
  35.         If RoleSet > Sheets(2).Cells(4, 3) Then
  36.             MsgBox "權限不足": Exit Function
  37.         ElseIf EndtRecTime > Now() Then
  38.             min = Int((Now() - EndtRecTime) / 24 / 60): sec = Int((Now() - EndtRecTime) / 24 / 60 / 60)
  39.             MsgBox "已在 " & Delay & " 分鐘內嘗試操作 " & LmtCnt & " 次,請於" & EndtRecTime & "後嘗試,剩下" & min & "分" & sec & "秒": Exit Function
  40.         ElseIf StartTime > Now() And Not (IsEmpty(StartTime)) Then
  41.             MsgBox "系統目前尚未開放!": Exit Function
  42.         ElseIf EndTime < Now() And Not (IsEmpty(EndTime)) Then
  43.             MsgBox "系統目前已關閉!": Exit Function
  44.         Else
  45.             .Cells(iRow, 13) = Now(): .Cells(iRow, 14) = .Cells(iRow, 13) + LmtCnt / 24 / 60
  46.         End If
  47.         If Count = 0 And EndtRecTime <= Now() Then
  48.             .Cells(iRow, 17) = 1
  49.         Else
  50.             .Cells(iRow, 17) = .Cells(iRow, 17) + 1
  51.         End If
  52.         If IsEmpty(Hack) Then
  53.             'If Xpos = 0 Or Ypos = 0 Then
  54.             '    InputBoxEr = InputBox(Prompt, Title, Default, , , HelpFile, Context)
  55.             'Else
  56.                 InputBoxEr = InputBox(Prompt, Title, Default, Xpos, Ypos, HelpFile, Context)
  57.             'End If
  58.         Else
  59.                 tmp = Sheets(2).Cells(5, 3): Sheets(2).Cells(5, 3) = Hack
  60.             'If Xpos = 0 Or Ypos = 0 Then
  61.             '    InputBoxEr = InputBoxDK(Prompt, Title, Default, , , HelpFile, Context)
  62.             'Else
  63.                 InputBoxEr = InputBoxDK(Prompt, Title, Default, Xpos, Ypos, HelpFile, Context)
  64.             'End If
  65.         End If
  66.             
  67.     End With
  68.     Sheets(2).Cells(5, 3) = tmp
  69. End Function
複製代碼
[attach]32376[/attach]




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)