大家好,我使用EXCEL寫了一個可以亂數出題的檔案,學員點選交卷後檔案會自動另存到一個指定路徑,使用我自己的電腦測試一切都正常,但寄給同事測試交卷時回出現錯誤訊息「執行階段錯誤'1004' 'Save As'方法('Workbook'物件)失敗,請問該怎麼排除?
``Private Sub CommandButton1_Click()
Dim i As Integer
Dim x As Integer
Dim y, z As Integer
Response = MsgBox("考券送出後無法再進行變更,是否確定交卷?", vbYesNo + vbQuestion)
If Response = vbYes Then
'送出答案回寫sheet2
sheet2.Cells(2, 5) = TextBox11.Value
sheet2.Cells(3, 5) = TextBox12.Value
sheet2.Cells(4, 5) = TextBox13.Value
sheet2.Cells(5, 5) = TextBox14.Value
sheet2.Cells(6, 5) = TextBox15.Value
sheet2.Cells(7, 5) = TextBox16.Value
sheet2.Cells(8, 5) = TextBox17.Value
sheet2.Cells(9, 5) = TextBox18.Value
sheet2.Cells(10, 5) = TextBox19.Value
sheet2.Cells(11, 5) = TextBox20.Value
y = sheet3.Range("H2") '扣分
z = 100
'比對答案
x = 2
For i = 21 To 30
If sheet2.Cells(x, 5) <> sheet2.Cells(x, 4) Then
Me("TextBox" & i).Value = sheet2.Cells(x, 4)
Me("TextBox" & i).BackColor = &HC0C0FF
sheet2.Cells(x, 6) = sheet2.Cells(x, 2)
z = z - y
Else
Me("TextBox" & i).Value = sheet2.Cells(x, 4)
End If
x = x + 1
Next
TextBox31.Value = z
sheet2.Range("I2") = z
ThisWorkbook.Save
TmpN1 = sheet2.Range("H2")
ActiveWorkbook.SaveAs Filename:="\Tsbnas2\檢測檔案" & TmpN1 & ".xls", FileFormat _
:=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:= _
False, CreateBackup:=False
CommandButton1.Enabled = False
End If
End Sub