สิ่งที่ต้องการคือต้องการ save as ทั้งไฟล์ excel เป็นไฟล์ใหม่และสร้าง folder หน้า Desktop โดยชื่อ folder แรก Desktop ให้เป็นชื่อ ใน Sheet (in) cloum C3 และเมื่อกดเข้าไปชื่อ ใน folder สอง ให้เป็นชื่อใน Sheet (in) cloum A3 ครับ แต่ตอนนี้ติดปัญหาคือ ผมไม่สามารถ save ได้ทั้งไฟล์ excel ทุกชีตครับแต่เหมือน save ออกมาแค่ชีทเดียวและสร้างขึ้นมาใหม่ เป็น ไฟล์ .csv แต่สิ่งที่ต้องการเป็นไฟล์ .xlsx ครับรบกวนอาจารย์และเพื่อนๆช่วยดูให้หน่อยครับ
Code: Select all
Private Sub CommandButton1_Click()
Dim csvFilePath As String, csvdirF As String, csvdirD As String, iCount As Long, jCount As Long, kCount As Long, maxRow As Long
Dim maxCol As Long, WSH As Variant, fileNo As Integer, FileNameT As String, FileNameD As String
Dim FTY, STN, ctno As Variant
FileNameT = Format(Now(), "hhmmss")
FileNameD = Format(Now(), "yyyymmdd")
Set WSH = CreateObject("WScript.Shell")
FTY = Worksheets("in").Cells(3, 3) 'factory
STN = Worksheets("in").Cells(3, 6) 'stlye
'row/cloum
ctno = Worksheets("in").Cells(1, 8).Value
csvdirF = WSH.SpecialFolders("Desktop") & "\" & FTY
csvdirD = csvdirF & "\" & FileNameD
csvFilePath = csvdirD & "\" & STN & "-CTNo." & ctno & "_" & FileNameT & ".csv"
maxRow = Cells(Rows.Count, 1).End(xlUp).Row
maxCol = Cells(2, Columns.Count).End(xlToLeft).Column
fileNo = FreeFile
Dim sc As Range, tg As Range
Dim tgBook As Workbook
With Sheets("IN")
lr = .Range("A" & Rows.Count).End(xlUp).Row
Set sc = .Range("A3:I10000" & lr)
sc.Copy
Sheets("Out").Range("A" & Rows.Count).End(xlUp).Offset(1, 0) _
.PasteSpecial xlPasteValues
Set tgBook = Workbooks.Open(Filename:="C:\Users\Administrator\Desktop\GF SYTEM\Data.xlsm")
sc.Copy
tgBook.Sheets(1).Range("A" & Rows.Count).End(xlUp).Offset(1, 0) _
.PasteSpecial xlPasteValues
ActiveWorkbook.Save
ActiveWorkbook.Close False
If Dir(csvdirF, vbDirectory) = "" Then
MkDir csvdirF
End If
If Dir(csvdirD, vbDirectory) = "" Then
MkDir csvdirD
End If
Open csvFilePath For Output As #fileNo
For iCount = 1 To maxRow
For jCount = 1 To maxCol - 1
If Not Cells(iCount, jCount) = "" Then
Write #fileNo, Cells(iCount, jCount);
End If
kCount = jCount
Next jCount
Write #fileNo, Cells(iCount, kCount + 1)
Next iCount
Close #fileNo
End With
Sheets("IN").Select
Range("A3:H1048576").Clear
Selection.ClearContents
Sheets("Out").Select
Range("A2:H1048576").Select
Selection.ClearContents
MsgBox "Done:"
Worksheets("IN").Select
Me.TextBox11.Text = Application.WorksheetFunction.Sum(Range("H3:H1048576"))
End Sub
You do not have the required permissions to view the files attached to this post.