Wednesday, February 6, 2019
Function แก้ไข date เพิ่ม0 และกำหนดรูปแบบ // Function select file and exec and insert to worksheet
Function Ndate(x, y, R)
A = Mid(x, 1, 2)
B = Mid(x, 4, 2)
R = R
newdate = DateAdd("d", 1, A & "-" & MonthName(B) & "-" & y)
A = Day(newdate)
If Len(A) = 1 Then
A = "0" & A
End If
B = Month(newdate)
If Len(B) = 1 Then
B = "0" & B
End If
Ndate = A & "/" & B
End Function
Sub FileOpenDialogBox()
'Display a Dialog Box that allows to select a single file.
'The path for the file picked will be stored in fullpath variable
With Application.FileDialog(msoFileDialogFilePicker)
'Makes sure the user can select only one file
.AllowMultiSelect = False
'Filter to just the following types of files to narrow down selection options
.Filters.Add "PDF Files", "*.pdf", 1
'Show the dialog box
.Show
'Store in fullpath variable
fullpath = .SelectedItems.Item(1)
End With
fullpath = """X:\Delivery Section\Test PDS_01\Print KB\pdftotext.exe""" + fullpath + " /to " + """X:\Delivery Section\Test PDS_01\Print KB\1.txt"""
'fullpath = "X:\Delivery Section\Test PDS_01\Print KB\pdftotext.exe"
'MsgBox fullpath
Shell fullpath, vbNormalFocus
Dim wbI As Workbook, wbO As Workbook
Dim wsI As Worksheet
Set wbI = ThisWorkbook
Set wsI = wbI.Sheets("PDF") '<~~ Sheet where you want to import
Set wbO = Workbooks.Open("X:\Delivery Section\Test PDS_01\Print KB\1.txt")
wbO.Sheets(1).Cells.Copy wsI.Cells
wbO.Close SaveChanges:=False
End Sub