35
« เมื่อ: 31 พ.ค. 62 , 11:47:20 »
ผมทำการ copy ไฟล์ และลบไฟล์เดิมทิ้ง
ปัญหามีว่า ไฟล์เดิม มันเปิดอยู่ คำสั่งไม่ทำงาน เราจะคำสั่งยังไง หากไฟล์เปิดอยู่ให้ปิดก่อนแล้วลบทิ้ง
***
Dim sPath, sfilename, sLink, sCopyInto, myOutput As String
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
sfilename = GetFileName
myOutput = Right(sfilename, Len(sfilename) - InStrRev(sfilename, "."))
sPath = GetFilePath
sLink = sPath & sfilename
'If Dir("CurrentProject.path & '\map\' & Me.NewName & '.' & myOutput", vbNormal) = "" Then
sCopyInto = [Forms]![manHisInsu]![folderInsu] & "\" & [Forms]![manHisInsu]![Even2] & "." & myOutput
fso.CopyFile sLink, sCopyInto
Set fso = Nothing
If sPath = [Forms]![manHisInsu]![folderInsu] & "\" Then
Else
Kill sLink
End If
MsgBox ("บันทึกเรียบร้อยแล้ว"), vbInformation, "ผลการทำงาน"
Exit_Command33_Click:
Exit Sub
Err_Command33_Click:
MsgBox " ไฟลนี้อาจเปิดอยู่ ให้ปิดไฟล์นี้เสียก่อน"
Resume Exit_Command33_Click