VBA Excel - Chuyển tất cả các ảnh vào trung tâm cell và 'Move and size with cells'
VBA Excel - Chuyển tất cả các ảnh vào trung tâm cell và 'Move and size with cells'
Sub CenterImages()
' Declare a variable to hold each shape in the worksheet
Dim shp As Shape
' Loop through all shapes in the active sheet
For Each shp In ActiveSheet.Shapes
' Check if the shape is a picture
If shp.Type = msoPicture Then
With shp
' Set the placement mode to "Move and Size with Cells"
.Placement = xlMoveAndSize
' Center the picture vertically in the cell
.Top = .TopLeftCell.Top + (.TopLeftCell.Height - .Height) / 2
' Center the picture horizontally in the cell
.Left = .TopLeftCell.Left + (.TopLeftCell.Width - .Width) / 2
End With
End If
Next shp
End Sub
Để sử dụng đoạn mã này:
- Mở Excel.
- Nhấn Alt + F11 để mở trình soạn thảo VBA.
- Chọn Insert > Module để tạo một module mới.
- Sao chép và dán đoạn mã trên vào module vừa tạo.
- Đóng trình soạn thảo VBA.
- Quay lại Excel, nhấn Alt + F8, chọn
CenterImages
và nhấn Run.
Nếu bài viết này hữu ích, anh em có thể mời mình cốc sinh tố lúa mạch theo số tài khoản TPbank 3355 3618 888 (quét QR). Để tạo ra 1 bài viết, mình mất trung bình 2-3 tiếng. Một sự ủng hộ hơn ngàn lời khích lệ, để mình có thể duy trì trang web và tạo ra nhiều bài viết chất lượng hơn. Trân trọng cảm ơn tình cảm của anh em!
Post a Comment