ผมเขียน code vba copy ไฟล์เพื่อสร้างใหม่ แต่มันขึ้น file not found ครับ
Posted: Fri Jun 03, 2022 2:26 pm
ผมเขียน code vba copy ไฟล์เพื่อสร้างใหม่ แต่มันขึ้น file not found ครับ
โค้ดตามนี้ครับอาจารย์
โค้ดตามนี้ครับอาจารย์
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