Excel宏 - 可以解释一下吗?

use*_*316 1 excel vba excel-2003

我是Excel宏的新手..

谁能告诉我这个宏有什么作用?

Sub People_Add_Document()

    prow = ActiveCell.row
    num = Cells(prow, 1).Value
    wshet = ActiveSheet.Name

    If (Val(num) > 0) _
       And (Cells(4, 1).Value = "#") _
       And (wsheet = People_wsheet) _
    Then
        people_select_link_to_Document process_wbook_path, prow
    End If
  End Sub



Sub people_select_link_to_Document(process_wbook_path, prow)

        If Len(Cells(prow, DocumentFile).Value) = 0 Then
        Fname = Application.GetOpenFilename("Document Files (*.doc;*.pdf),*.doc;*.pdf", 1, "Select the Document file..")

        If Fname <> False Then

            Cells(prow, DocumentFile).Value = Fname 'global path

        End If

    End If

End Sub
Run Code Online (Sandbox Code Playgroud)

Dav*_*nan 5

获取活动单元格的行号:

prow = ActiveCell.row
Run Code Online (Sandbox Code Playgroud)

获取该行第1列中的值:

num = Cells(prow, 1).Value
Run Code Online (Sandbox Code Playgroud)

阅读活动工作表的名称(此处有错误,应该读取wsheet而不是wshet):

wshet = ActiveSheet.Name
Run Code Online (Sandbox Code Playgroud)

测试if num是否大于0,并且单元格A4包含"#"并且活动工作表等于调用的变量或常量People_wsheet.如果是这样,一个调用的子程序people_select_link_to_Document被调用,参数process_wbook_pathprow

If (Val(num) > 0) _
   And (Cells(4, 1).Value = "#") _
   And (wsheet = People_wsheet) _
Then
    people_select_link_to_Document process_wbook_path, prow
End If
Run Code Online (Sandbox Code Playgroud)

现在,该子例程首先检查DocumentFile活动行的列是否为空.实际上,这是测试空虚的一种相当蹩脚的方法,但它可能会这样做.

    If Len(Cells(prow, DocumentFile).Value) = 0 Then
Run Code Online (Sandbox Code Playgroud)

如果它是空的,那么我们显示一个文件对话框来获取文件名:

    Fname = Application.GetOpenFilename("Document Files (*.doc;*.pdf),*.doc;*.pdf", 1, "Select the Document file..")
Run Code Online (Sandbox Code Playgroud)

如果已选择文件名(即未取消对话框),则我们将该文件名保存DocumentFile在活动行的列中以供将来参考:

    If Fname <> False Then

        Cells(prow, DocumentFile).Value = Fname 'global path

    End If
Run Code Online (Sandbox Code Playgroud)

就是这样!