Page 1 of 1

ผมเขียน code vba copy ไฟล์เพื่อสร้างใหม่ แต่มันขึ้น file not found ครับ

Posted: Fri Jun 03, 2022 2:26 pm
by 10idlnw
ผมเขียน code vba copy ไฟล์เพื่อสร้างใหม่ แต่มันขึ้น file not found ครับ
โค้ดตามนี้ครับอาจารย์
copyfile.xlsm

Code: Select all



Private Sub CommandButton1_Click()

Dim str1 As String
Dim str2 As String
Dim mypath As String
Dim strFileExists As String
Dim filenames As String

    mypath = ThisWorkbook.path & "\"
    filenames = Range("G7")
    str1 = mypath & filenames & ".xlsm"
    str2 = mypath & txt1.Value & "-" & txt2.Value & "-" & txt3.Value & ".xlsm"
    strFileExists = Dir(str2)
    
    If strFileExists = "" Then
        FileCopy str1, str2
        MsgBox "สร้างไฟล์สำเร็จ"
    Else
        MsgBox "ไฟล์นี้น่าจะอยู่แล้วกรุณาตรวจสอบใหม่อีกครั้ง"
    End If
End Sub



Re: ผมเขียน code vba copy ไฟล์เพื่อสร้างใหม่ แต่มันขึ้น file not found ครับ

Posted: Fri Jun 03, 2022 2:36 pm
by snasui
:D เซลล์ G7 มีวรรคอยู่ด้านหน้า ลองลบวรรคทิ้งไปดูก่อนครับ

Re: ผมเขียน code vba copy ไฟล์เพื่อสร้างใหม่ แต่มันขึ้น file not found ครับ

Posted: Fri Jun 03, 2022 3:33 pm
by 10idlnw
เบื้องต้น ตรวจสอบแล้ว ใช่ครับ ใช้งานได้แล้วครับ ขอบคุณมากครับอาจารย์