台灣最大程式設計社群網站
線上人數
1433
 
會員總數:246037
討論主題:189624
歡迎您免費加入會員
討論區列表 >> 其他語言 >> 我是新手在請各位熟手幫我看看哪裡錯了!!vba
[]  
[我要回覆]
1
回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
我是新手在請各位熟手幫我看看哪裡錯了!!vba
價值 : 5 QP  點閱數:225 回應數:4
樓主

jho20186
門外漢
0 2
60 1
發送站內信

因公司需求我做了了一張表單,但現都顯示"此處需要物件"可以請各位熟手幫幫忙看一下如何修正嗎?

Dim D As String
Dim T As String
T = Left(ActiveWorkbook.Name, 5) + "檢查\"
If TextBox5.Text = "" And Not (TextBox6.Text = "") Then
If IsDate(TextBox6.Text) And TextBox6.TextLength = 9 Then
Cells(4, "E") = "訂單編號:" & TextBox1.Text
Cells(5, "F") = TextBox2.Text
Cells(4, "H") = TextBox3.Text
Cells(5, "H") = TextBox4.Text
Cells(4, "J") = TextBox5.Text
Cells(5, "J") = TextBox6.Text
MsgBox "資料輸入成功"
E = Left(ActiveWorkbook.Name, 20)
D = E + "_進料檢驗表單_Range(B5)--" + Left(TextBox6.Text, 3) + Mid(TextBox6.Text, 5, 2) + Mid(TextBox6.Text, 8, 2) + "生產(" + TextBox1.Text + "--" + TextBox2.Text + "-" + TextBox4.Text + ")"
ActiveWorkbook.SaveAs Filename:="\\Charmingal\品檢\C\031\3\" + T + D & xlBook.xlSheet.Range(D) & ".xls"
Workbooks(ActiveWorkbook.Name).SaveAs "\\Charmingal\品檢\C\031\3\" + T + D
QC_FORM.Hide
Else
MsgBox "日期錯誤!!"
End If
End If

If TextBox6.Text = "" And Not (TextBox5.Text = "") Then
If IsDate(TextBox5.Text) And TextBox5.TextLength = 9 Then
Cells(4, "E") = "訂單編號:" & TextBox1.Text
Cells(5, "F") = TextBox2.Text
Cells(4, "H") = TextBox3.Text
Cells(5, "H") = TextBox4.Text
Cells(4, "J") = TextBox5.Text
Cells(5, "J") = TextBox6.Text
MsgBox "資料輸入成功"
E = Left(ActiveWorkbook.Name, 20)
D = E + "_進料檢驗表單_RimProfile--" + Left(TextBox6.Text, 3) + Mid(TextBox6.Text, 5, 2) + Mid(TextBox6.Text, 8, 2) + "生產(" + TextBox1.Text + "--" + TextBox2.Text + "-" + TextBox4.Text + ")"
ActiveWorkbook.SaveAs Filename:="\\Charmingal\品檢\C\031\3\" + T + D & xlBook.xlSheet.Range(D) & ".xls"
Workbooks(ActiveWorkbook.Name).SaveAs "\\Charmingal\品檢\C\031\3\" + T + D
QC_FORM.Hide
Else
MsgBox "進貨日期錯誤!!"
End If
End If

If TextBox6.Text = "" And TextBox5.Text = "" Then
Cells(4, "E") = "訂單編號:" & TextBox1.Text
Cells(5, "F") = TextBox2.Text
Cells(4, "H") = TextBox3.Text
Cells(5, "H") = TextBox4.Text
Cells(4, "J") = TextBox5.Text
Cells(5, "J") = TextBox6.Text
MsgBox "資料輸入成功"
E = Left(ActiveWorkbook.Name, 20)

D = E + "_進料檢驗表單_RimProfile--" + Left(TextBox6.Text, 3) + Mid(TextBox6.Text, 5, 2) + Mid(TextBox6.Text, 8, 2) + "生產(" + TextBox1.Text + "--" + TextBox2.Text + "-" + TextBox4.Text + ")"
Workbooks(ActiveWorkbook.Name).SaveAs "\\Charmingal\品檢\C\031\3\" + T + D
QC_FORM.Hide
End If

If Not (TextBox6.Text = "") And Not (TextBox5.Text = "") Then
If IsDate(TextBox5.Text) And TextBox5.TextLength = 9 And IsDate(TextBox6.Text) And TextBox6.TextLength = 9 Then
Cells(4, "E") = "訂單編號:" & TextBox1.Text
Cells(5, "F") = TextBox2.Text
Cells(4, "H") = TextBox3.Text
Cells(5, "H") = TextBox4.Text
Cells(4, "J") = TextBox5.Text
Cells(5, "J") = TextBox6.Text
MsgBox "資料輸入成功"
E = Left(ActiveWorkbook.Name, 20)
D = E + "_進料檢驗表單_Range(B5)--" + Left(TextBox6.Text, 3) + Mid(TextBox6.Text, 5, 2) + Mid(TextBox6.Text, 8, 2) + "生產(" + TextBox1.Text + "--" + TextBox2.Text + "-" + TextBox4.Text + ")"
xlBook.SaveAs Filename:="\\Charmingal\品檢\C\031\3\" + T + D & xlBook.xlSheet.Range("D") & ".xls"
Workbooks(ActiveWorkbook.Name).SaveAs "\\Charmingal\品檢\C\031\3\" + T + D
QC_FORM.Hide
Else
MsgBox "日期錯誤!!"
End If
End If

搜尋相關Tags的文章: [ 顯示"此處需要物件" ] ,
本篇文章發表於2020-06-29 14:22
1樓
回應

Allen
捐贈 VP 給 Allen 檢舉此回應
應該會告知第幾行錯誤吧?
本篇文章回覆於2020-06-29 18:43
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
2樓
回應

香帥
檢舉此回應
Textbox沒指定是哪一個userform的,可能會發生找不到物件,因此產生此處需要物件
尤其是多表單,例如有些表單有textbox3,有些沒有,在沒有textbox3表單內的程式碼
就會發生錯誤
本篇文章回覆於2020-06-29 23:13
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
3樓
回應

香帥
檢舉此回應
再補充一下,除了上述多表單外,
在單一表單因您沒用userform1.去顯示各textbox來選擇
容易打錯例如表單只有textbox3,程式碼應該打textbox3.text卻打錯成Textbos3.text或打成textbox33.text
執行時也會產生此處需要物件的錯誤
本篇文章回覆於2020-06-29 23:25
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
4樓
作者回應

jho20186
檢舉此回應
那請問各位如果我要把D = E + "_進料檢驗表單_Range(B5)--" + Left(TextBox6.Text, 3) + Mid(TextBox6.Text, 5, 2) + Mid(TextBox6.Text, 8, 2) + "生產(" + TextBox1.Text + "--" + TextBox2.Text + "-" + TextBox4.Text + ")"顯示成為資料夾的檔名,Range(B5)要如何設定成為我想要的名稱??因為我希望Range(B5)這裡可以隨著我要的檔案名稱做變動??
本篇文章回覆於2020-06-30 17:04
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
   
1

回覆
如要回應,請先登入.