Public Sub XulyChenAnhBenNgoai(DuongDan, TenFile)
ReDim Arr_Image(1 To 1000, 1 To 4)
Dim Arr()
Dim Obj1, GetAName
[COLOR=#ff0000][B] Set Obj1 = CreateObject("Scripting.FileSystemObject")[/B][/COLOR]
Dim RwC As Long, ColC As Long, i As Long, x As Byte
Dim Path_Images As String, Path_rels As String
RwC = Sheet1.UsedRange.Rows.Count
ColC = Sheet1.UsedRange.Columns.Count
Arr = Sheet1.Range(Cells(1, 1), Cells(RwC, ColC)).Value
'lay link hinh anh vao mang
For i = Row_Type + 2 To RwC
If Len(Arr(i, Col_Image)) > 0 Then
x = x + 1
Arr_Image(x, 1) = Arr(i, Col_Image) 'C:\VanTan\Image1.png
Arr_Image(x, 2) = Function_NameFiles(Arr_Image(x, 1), 1) 'Image1.png
Arr_Image(x, 3) = Function_NameFiles(Arr_Image(x, 1), 2) 'Image1
Arr_Image(x, 4) = Function_NameFiles(Arr_Image(x, 1), 3) 'png
End If
Next i
'Ten 2 duong dan image va _rels
Path_Images = DuongDan & "\images"
Path_rels = DuongDan & "\_rels"
'neu co 2 thu muc do thi xoa di
If Obj1.FolderExists(Path_Images) Then _
Obj1.DeleteFolder Path_Images
Path_rels = DuongDan & "\_rels"
If Obj1.FolderExists(Path_rels) Then _
Obj1.DeleteFolder Path_rels
'Neu khong co hinh anh nao duoc chen ti thoat Sub
If x = 0 Then Exit Sub
'Tao thu muc images
MkDir Path_Images
'copy hinh anh tu duong dan vao thu muc vua tao
For i = 1 To x
FileCopy Arr_Image(i, 1), Path_Images & "\" & Arr_Image(i, 2)
Next i
'tao thu muc _rels
MkDir Path_rels
'tao file customUI.xml.rels
[COLOR=#ff0000][B] Const ForReading = 1, ForWriting = 2, ForAppending = 8[/B]
[B] Set GetAName = Obj1.OpenTextFile(Path_rels & "\" & TenFile & ".rels", ForWriting, True)[/B]
[B] With GetAName[/B]
[B] .Write Get_RELS(Arr_Image, x)[/B]
[B] .Close[/B]
[B] End With[/B][/COLOR]
End Sub