Như chúng ta đã biết, đôi lúc trong Excel có những công việc tương tự nhau lặp đi lại nhiều lần. Khi đó chúng ta sẽ nghĩ ra một cách nào đó để thực hiện nó một cách nhanh chóng và đỡ mất nhiều thời gian. Hôm nay tôi sẽ hướng dẫn các bạn thực hiện việc đó một cách dễ dàng trong excel thông qua việc lập trình VBA.
Các bạn có thể tải nguồn tại đây để xem trước https://mega.co.nz/#!Hx5UATRD!eDzo821qxfXGFKY2RAls7WW3fjWNyfX0mXuZBQGTBNA
'ham main, dùng để gọi các àm con của chương trình nơi chính để thực hiện chường trình.
Sub Main()
Application.ScreenUpdating = False
UserForm1.Show
Application.ScreenUpdating = True
End Sub
'tìm xóa các link không có trong trang
Sub DeleteBrokenLinks()
'ActiveSheet.Hyperlinks.Delete
On Error Resume Next
For Each alink In Cells.Hyperlinks
strURL = alink.Address
If (InStr(strURL, "file") > 0 Or InStr(strURL, ".") > 0 Or InStr(strURL, "http") > 0) Then
alink.Parent.Hyperlinks.Delete
End If
Next alink
End Sub
'set page printer theo các giá tri
Sub SetPagePrinter()
ActiveWindow.View = xlPageBreakPreview
ActiveSheet.PageSetup.PrintArea = "$A$1:$" & ColLetter(LastColumn) & "$" & LastRow
End Sub
'dua con tro vè dâu trang
Sub GoHomePage()
ActiveSheet.Range("A1").Select
End Sub
'thiet lap zoom cho trang với thông số sẽ được người dùng nhập trực tiếp.
Sub ZoomPage(value As Byte)
ActiveWindow.Zoom = value
End Sub
'lay dong cuoi cung co gia tri
Function LastRow() As Long
With ActiveSheet.UsedRange
LastRow = .Rows(.Rows.Count).Row
End With
End Function
'lay cot cuoi co gia tri
Function LastColumn() As Long
With ActiveSheet.UsedRange
LastColumn = .Columns(.Columns.Count).Column
End With
End Function
'hàm nhan ve ten column voi tham so la so cot cuoi
Function ColLetter(ColNumber As Integer) As String
ColLetter = Left(Cells(1, ColNumber).Address(False, False), _
1 - (ColNumber > 26))
End Function
Sub ListLinks()
Dim i As Byte
On Error Resume Next
For Each alink In Cells.FollowHyperlink
strURL = alink.Address
Cells(i, 1) = strURL
i = i + 1
Next alink
End Sub
Các bạn có thể tải nguồn tại đây để xem trước https://mega.co.nz/#!Hx5UATRD!eDzo821qxfXGFKY2RAls7WW3fjWNyfX0mXuZBQGTBNA
'ham main, dùng để gọi các àm con của chương trình nơi chính để thực hiện chường trình.
Sub Main()
Application.ScreenUpdating = False
UserForm1.Show
Application.ScreenUpdating = True
End Sub
'tìm xóa các link không có trong trang
Sub DeleteBrokenLinks()
'ActiveSheet.Hyperlinks.Delete
On Error Resume Next
For Each alink In Cells.Hyperlinks
strURL = alink.Address
If (InStr(strURL, "file") > 0 Or InStr(strURL, ".") > 0 Or InStr(strURL, "http") > 0) Then
alink.Parent.Hyperlinks.Delete
End If
Next alink
End Sub
'set page printer theo các giá tri
Sub SetPagePrinter()
ActiveWindow.View = xlPageBreakPreview
ActiveSheet.PageSetup.PrintArea = "$A$1:$" & ColLetter(LastColumn) & "$" & LastRow
End Sub
'dua con tro vè dâu trang
Sub GoHomePage()
ActiveSheet.Range("A1").Select
End Sub
'thiet lap zoom cho trang với thông số sẽ được người dùng nhập trực tiếp.
Sub ZoomPage(value As Byte)
ActiveWindow.Zoom = value
End Sub
'lay dong cuoi cung co gia tri
Function LastRow() As Long
With ActiveSheet.UsedRange
LastRow = .Rows(.Rows.Count).Row
End With
End Function
'lay cot cuoi co gia tri
Function LastColumn() As Long
With ActiveSheet.UsedRange
LastColumn = .Columns(.Columns.Count).Column
End With
End Function
'hàm nhan ve ten column voi tham so la so cot cuoi
Function ColLetter(ColNumber As Integer) As String
ColLetter = Left(Cells(1, ColNumber).Address(False, False), _
1 - (ColNumber > 26))
End Function
Sub ListLinks()
Dim i As Byte
On Error Resume Next
For Each alink In Cells.FollowHyperlink
strURL = alink.Address
Cells(i, 1) = strURL
i = i + 1
Next alink
End Sub
