hung2412
Thành viên tích cực
- Tham gia
- 5/8/08
- Bài viết
- 929
- Được thích
- 240
- Giới tính
- Nam
Nếu chỉ lấy "Public"
If line Like "Public *" Then
Nếu muốn lấy hết phần khai báo biến (trong sub):
If line Like "Public *" Or line Like "Dim *" Or line Like "Conts *" Then
Option Explicit
Public i As Long
Public rng As Range
Public Tam
Public Dic As Object
Public k As String
Sub Hoi_cach_Module1_da_khai_bao_vao_o_Cell()
Dim code As String, lines, line
code = ThisWorkbook.VBProject.VBComponents("Lay_ten_bien").CodeModule.lines(1, _
ThisWorkbook.VBProject.VBComponents("Lay_ten_bien").CodeModule.CountOfLines)
lines = Split(code, vbCrLf)
For Each line In lines
'If line Like "Public *" Then
If line Like "Public *" Or line Like "Dim *" Or line Like "Conts *" Then
Range("B1000").End(xlUp).Offset(1, 0).Value = line
End If
Next
End Sub
Cảm ơn bạn.code = ThisWorkbook.VBProject.VBComponents("Lay_ten_bien").CodeModule.lines(1, _
ThisWorkbook.VBProject.VBComponents("Lay_ten_bien").CodeModule.CountOfLines)
Sub InThongTinBienTrongDuAns()
Dim vbProj As Object
Dim vbComp As Object
Dim vbModule As Object
Dim lineNum As Long
Dim codeLine As String
Set vbProj = Application.VBE.ActiveVBProject
For Each vbComp In vbProj.VBComponents
If vbComp.CodeModule.CountOfLines > 0 Then
Set vbModule = vbComp.CodeModule
For lineNum = 1 To vbModule.CountOfLines
codeLine = vbModule.lines(lineNum, 1)
If Left(codeLine, Len("Public")) = "Public" Then
Debug.Print codeLine
End If
Next lineNum
End If
Next vbComp
End Sub
Bạn tự chế biến để in xuống sheets.PHP:Sub InThongTinBienTrongDuAns() Dim vbProj As Object Dim vbComp As Object Dim vbModule As Object Dim lineNum As Long Dim codeLine As String Set vbProj = Application.VBE.ActiveVBProject For Each vbComp In vbProj.VBComponents If vbComp.CodeModule.CountOfLines > 0 Then Set vbModule = vbComp.CodeModule For lineNum = 1 To vbModule.CountOfLines codeLine = vbModule.lines(lineNum, 1) If Left(codeLine, Len("Public")) = "Public" Then Debug.Print codeLine End If Next lineNum End If Next vbComp End Sub
Không bạn ơi. (Gõ cho thêm ký tự)View attachment 297161
tôi chạy thì được như này, chủ thớt hông rõ có cần liệt kê biến local hông nhỉ?