
Gửi bởi
mrzuzes
Dạ đúng thứ em cần rồi anh , anh có thể giúp em thêm 1 chút không anh. Em muốn cái phần hình ảnh nó to ra thệm thì làm cách nào ạ, với phần tên bỏ đi cái định dạng của file ảnh "abcz.jpg" em muốn bỏ phần định dạng của file ảnh đi chỉ còn tên thôi dc không Anh
Bạn thay toàn bộ code bài trên thành code sau nhé:
Mã nguồn PHP:
Option ExplicitSub Main() Dim vFile, picItem Dim path As String, ret As String Dim rng As Range Dim n As Long vFile = Application.GetOpenFilename("Image Files, *.bmp;*.jpg;*.png", , , , True) If IsArray(vFile) Then Set rng = Sheet1.Range("E60000").End(xlUp).Offset(1) For Each picItem In vFile path = CStr(picItem) ret = Pic2Comment(path, rng.Offset(n, -2)) rng.Offset(n, 0).Value = ret n = n + 1 Next End IfEnd SubPrivate Function Pic2Comment(ByVal path As String, ByVal cel As Range) As String Dim fso As Object On Error Resume Next Set fso = CreateObject("Scripting.FileSystemObject") With cel .ClearComments If fso.FileExists(path) Then .AddComment: .Comment.Visible = True With .Comment.Shape .Shadow.Visible = msoFalse .Line.ForeColor.RGB = vbWhite .AutoShapeType = msoShapeRectangle .Left = cel.Left: .Top = cel.Top .Width = cel.Width: .Height = cel.Height .ScaleWidth 1, msoFalse, msoScaleFromMiddle ' Chinh độ rộng của ảnh ở đây .ScaleHeight 1, msoFalse, msoScaleFromMiddle ' Chỉnh độ cao của ảnh ở đây .Fill.UserPicture path End With If Err.Number = 0 Then Pic2Comment = fso.GetBaseName(path) 'Pic2Comment = fso.GetFile(path).Name Else cel.Comment.Delete End If End If End WithEnd FunctionSub DelComm() Sheet1.Range("C5:C60000").ClearCommentsEnd Sub
Chỗ tô màu đỏ là chỗ tôi có chỉnh lại theo yêu cầu của bạn.
Chi tiết, bạn xem file đính kèm nhé.