của bạn đây:
Phần 1:
Option Explicit
' Chon biên tên_file_chon(1 To 100) nham muc dich giai phóng bô nho cua KQ thôi
Public tên_file_chon(1 To 100) As String '100 files is the maximum applying this code
Public i As Integer
Sub ABC()
' ----------------------------------------------------- '
' Tao cac ban VietPharse Edit '
' Write by: duongthanh85 '
' Y!M & Skype: duongthanhhtd '
' Email:
duongdinhthanh@gmail.com '
' Blog:
www.360.yahoo.com/duongthanhhtd '
' ----------------------------------------------------- '
Dim CheckFile As Boolean
Dim k As Integer
Dim j As Integer
Dim Page_hiên_tai As Integer
'call a routine that removes all settings from the find dialog
'so future users of the dialog won't get strange results
' Call ClearFindAndReplaceParameters
Page_hiên_tai = 0
'get current page
Page_hiên_tai = Selection.Information(wdActiveEndAdjustedPageNumber)
Call FileDialogOpen_Multi
For j = 1 To i Step 1
CheckFile = VerifyFileABC(tên_file_chon(j))
If tên_file_chon(j) <> vbNullString And CheckFile = True Then
'MsgBox "ok xxxxxxxxxx: " & tên_file_chon(j)
Call trans1(tên_file_chon(j))
Else
' Châm dut
End
End If
Next
' vÊ lai trang hiên thi truoc dó
Selection.GoTo what:=wdGoToPage, Which:=wdGoToNext, Name:=Page_hiên_tai
End Sub
Function VerifyFileABC(FileName As String) As Boolean
' ----------------------------------------------------- '
' Kiem tra su ton tai cua mot file '
' Write by: duongthanh85 '
' Y!M & Skype: duongthanhhtd '
' Email:
duongdinhthanh@gmail.com '
' Blog:
www.360.yahoo.com/duongthanhhtd '
' ----------------------------------------------------- '
On Error Resume Next
Open FileName For Input As #1
If Err Then
MsgBox ("File: " & FileName & " Khong ton tai, kiem tra lai duong dan file data !! Hoac ban da huy chon file.")
VerifyFileABC = False
Else
VerifyFileABC = True
End If
Close #1
End Function
Sub FileDialogOpen_Multi()
Dim MyDialog As FileDialog
Dim Tâp_hop_cac_tên_file As Variant
Dim KQ As Variant
'On Error Resume Next
Set MyDialog = Application.FileDialog(msoFileDialogFilePicker)
With MyDialog
.Filters.Clear
.Filters.Add "All EXELL File ", "*.xls", 1
.AllowMultiSelect = True
i = 1
If .Show = -1 Then
For Each Tâp_hop_cac_tên_file In .SelectedItems
tên_file_chon(i) = Tâp_hop_cac_tên_file
i = i + 1
Next
i = i - 1
' ReDim tên_file_chon(Tâp_hop_cac_tên_file)
Else
MsgBox "Ban chua chon file."
End
End If
End With
End Sub