snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
Sub addsheet_Link_BR()
Dim i As Integer
Dim lastrow As Integer
Dim MyFile As String, Str As String, MyDir As String, Wb As Workbook
Dim Rws As Long, Rng As Range
Set Wb = ThisWorkbook
'change the address to suite
Do While MyFile <> ""
Workbooks.Open (MyFile)
With Worksheets("Rp-Cpx")
Sheets("Rp-Cpx").Select
Range("D1").Select
Range("D1:S146").Select
Application.CutCopyMode = False
Selection.Copy
Windows("ทดลอง3.xlsm").Activate
Range("D1").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Range("D1").Select
Windows(MyFile).Activate
ActiveWorkbook.Close True
End With
MyFile = Dir()
Loop
Next i
End Sub
Sub Test()
MsgBox GetFolder("C:\TEST_INITIAL\")
End Sub
Function GetFolder(strPath As String) As String
Dim fldr As FileDialog
Dim sItem As String
Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
With fldr
.Title = "Select a Folder"
.AllowMultiSelect = False
.InitialFileName = strPath
If .Show <> -1 Then GoTo NextCode
sItem = .SelectedItems(1)
End With
NextCode:
Range("B1").Value = fldr.SelectedItems(1)
GetFolder = sItem
Set fldr = Nothing