snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
'------- {Module1} ------------
Public Test as String
Test = "สวัสดีครับนี่คือ Sub "
Sub MyA()
msgbox Test & "A"
End Sub
Sub MyB()
msgbox Test & "B"
End Sub
Sub MyC()
msgbox Test & "C"
End Sub
'------- {Module1} ------------
Public Const TestPath As String = ThisWorkbook.Path & "\"
Sub MyA()
Range("a1") = TestPath & " MyA"
End Sub
Sub MyB()
Range("a2") = TestPath & " MyB"
End Sub
Sub MyC()
Range("a3") = TestPath & " MyC"
End Sub
ผมลองแล้วมันขึ้น Error ตามภาพครับอาจารย์
2022-07-02_7-29-54.jpg
test.xlsm
You do not have the required permissions to view the files attached to this post.
Public TestPath As String
Sub MyA()
Range("a1") = TestPath & " MyA"
End Sub
Sub MyB()
TestPath = ThisWorkbook.Path & "\"
Range("a2") = TestPath & " MyB"
End Sub
Sub MyC()
Range("a3") = TestPath & " MyC"
End Sub
ผลลัพธ์ที่ได้
You do not have the required permissions to view the files attached to this post.