[ Cần giúp đỡ ] Chỉnh code cách chọn tên folder (1 người xem)

Liên hệ QC

Người dùng đang xem chủ đề này

Datcdt2k9

Thành viên hoạt động
Tham gia
27/12/19
Bài viết
109
Được thích
11
Em chào mọi người
Em có file excel tham khảo trên mạng lấy tên file trong folder nhưng mỗi lần lại phải click vào mũi tên khoanh đỏ để chọn folder, nhờ các anh chị giúp em sửa code để em có thể thay đường link folder cố định thay vì phải bấm vào mũi tên kia để chọn folder ạ
1634049977100.png
 

File đính kèm

Lần chỉnh sửa cuối:
Em chào mọi người
Em có file excel tham khảo trên mạng lấy tên file trong folder nhưng mỗi lần lại phải click vào mũi tên khoanh đỏ để chọn folder, nhờ các anh chị giúp em sửa code để em có thể thay đường link folder cố định thay vì phải bấm vào mũi tên kia để chọn folder ạ
View attachment 267607
Đoạn này nè. Dòng nào thừa tôi đã chuyển sang dạng ghi chú.
Rich (BB code):
'    ' Open folder dialog window
'    Application.FileDialog(msoFileDialogFolderPicker).Title = " Select foler"
'    intDialogue = Application.FileDialog(msoFileDialogFolderPicker).Show
    strPath = "D:\Temp" 'Thay duong dan cung vao day
    
    ' Retrieve the list of files
'    If intDialogue <> 0 Then
'        strPath = Application.FileDialog(msoFileDialogFolderPicker).SelectedItems(1)
        Application.StatusBar = "Detecting count of files..."
        lngFiles = CountFiles(strPath)
        ReDim varFileList(1 To lngFiles, 1 To ActiveWorkbook.Worksheets(1).ListObjects("tab_files").DataBodyRange.Columns.Count)
        Set objFso = CreateObject("Scripting.FileSystemObject")
        lngRowCount = RetrieveFiles(strPath, objFso, 1)
        RetrieveFolders strPath, objFso, lngRowCount
'    End If
 
Đoạn này nè. Dòng nào thừa tôi đã chuyển sang dạng ghi chú.
Rich (BB code):
'    ' Open folder dialog window
'    Application.FileDialog(msoFileDialogFolderPicker).Title = " Select foler"
'    intDialogue = Application.FileDialog(msoFileDialogFolderPicker).Show
    strPath = "D:\Temp" 'Thay duong dan cung vao day
   
    ' Retrieve the list of files
'    If intDialogue <> 0 Then
'        strPath = Application.FileDialog(msoFileDialogFolderPicker).SelectedItems(1)
        Application.StatusBar = "Detecting count of files..."
        lngFiles = CountFiles(strPath)
        ReDim varFileList(1 To lngFiles, 1 To ActiveWorkbook.Worksheets(1).ListObjects("tab_files").DataBodyRange.Columns.Count)
        Set objFso = CreateObject("Scripting.FileSystemObject")
        lngRowCount = RetrieveFiles(strPath, objFso, 1)
        RetrieveFolders strPath, objFso, lngRowCount
'    End If
Bạn có thể sửa giúp mình chỉ cần open file excel là sẽ tự động chạy code thay vì phải bấm vào mũi tên kia ạ
 

File đính kèm

Gọi sub RetrieveFilesandFolders từ sự kiện Workbook_Ope

Gọi sub RetrieveFilesandFolders từ sự kiện Workbook_Open
Vì 1 lý do mà mình cần tạo mới file excel. Mình copy nguyên code VBA từ module file gốc sang một file excel mới mà code vẫn chạy bình thường nhưng khi chạy xong không có data được export ra file exccel.Bạn giúp mình kiểm tra và sửa code sao cho giống với file excel ban đầu với ạ
 

File đính kèm

Vì 1 lý do mà mình cần tạo mới file excel. Mình copy nguyên code VBA từ module file gốc sang một file excel mới mà code vẫn chạy bình thường nhưng khi chạy xong không có data được export ra file exccel.Bạn giúp mình kiểm tra và sửa code sao cho giống với file excel ban đầu với ạ
Tôi không hiểu giống với file ban đầu là file nào?
 
Đoạn này nè. Dòng nào thừa tôi đã chuyển sang dạng ghi chú.
Rich (BB code):
'    ' Open folder dialog window
'    Application.FileDialog(msoFileDialogFolderPicker).Title = " Select foler"
'    intDialogue = Application.FileDialog(msoFileDialogFolderPicker).Show
    strPath = "D:\Temp" 'Thay duong dan cung vao day
  
    ' Retrieve the list of files
'    If intDialogue <> 0 Then
'        strPath = Application.FileDialog(msoFileDialogFolderPicker).SelectedItems(1)
        Application.StatusBar = "Detecting count of files..."
        lngFiles = CountFiles(strPath)
        ReDim varFileList(1 To lngFiles, 1 To ActiveWorkbook.Worksheets(1).ListObjects("tab_files").DataBodyRange.Columns.Count)
        Set objFso = CreateObject("Scripting.FileSystemObject")
        lngRowCount = RetrieveFiles(strPath, objFso, 1)
        RetrieveFolders strPath, objFso, lngRowCount
'    End If
Vẫn là bài ban đầu bên trên code mình nhờ bạn chỉnh sửa, khi mình tạo file mới và copy y chang module sang mà không được.
Gọi sub RetrieveFilesandFolders từ sự kiện Workbook_Open
File ban đầu là file này bạn ạ, mình copy y chang 2 mudule trong file này, dán sang file excel tạo mới mà không export được data
 
Vẫn là bài ban đầu bên trên code mình nhờ bạn chỉnh sửa, khi mình tạo file mới và copy y chang module sang mà không được.

File ban đầu là file này bạn ạ, mình copy y chang 2 mudule trong file này, dán sang file excel tạo mới mà không export được data

Trong code tôi thấy có tham chiếu tới cái tên "tab-files". Trong file mới bạn có đặt tên table giống vậy chưa?

.ListObjects("tab_files")....
 
Ok
Trong code tôi thấy có tham chiếu tới cái tên "tab-files". Trong file mới bạn có đặt tên table giống vậy chưa?

.ListObjects("tab_files")....

Trong code tôi thấy có tham chiếu tới cái tên "tab-files". Trong file mới bạn có đặt tên table giống vậy chưa?

.ListObjects("tab_files")....
Mình cảm ơn bạn nhé
 
Web KT

Bài viết mới nhất

Back
Top Bottom