Excel 宏 - 谁能解释一下?

发布于 2024-10-21 03:23:57 字数 765 浏览 3 评论 0原文

我是 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

I am new to Excel macros..

Can anyone tell me what this macro does?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

末蓝 2024-10-28 03:23:57

获取活动单元格的行号:

prow = ActiveCell.row

获取该行第1列的值:

num = Cells(prow, 1).Value

读取活动工作表的名称(这里有一个错误,应该读取wsheet而不是wshet< /code>):

wshet = ActiveSheet.Name

测试 num 是否大于 0,并且单元格 A4 包含“#”,并且活动工作表是否等于名为 People_wsheet 的变量或常量。如果是这样,则使用参数 process_wbook_pathprow 调用名为 people_select_link_to_Document 的子例程。

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

现在,该子例程首先检查 活动行的 >DocumentFile 列为空。实际上,这是一种相当蹩脚的测试空性的方法,但它可能会起作用。

    If Len(Cells(prow, DocumentFile).Value) = 0 Then

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

    Fname = Application.GetOpenFilename("Document Files (*.doc;*.pdf),*.doc;*.pdf", 1, "Select the Document file..")

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

    If Fname <> False Then

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

    End If

就是这样!

Get the row number of the active cell:

prow = ActiveCell.row

Get the value in column 1 of that row:

num = Cells(prow, 1).Value

Read the name of the active worksheet (there is an error here, should read wsheet rather than wshet):

wshet = ActiveSheet.Name

Test if num is greater than 0, and the cell A4 contains "#" and the active worksheet is equal to a variable or constant called People_wsheet. And if so, a subroutine called people_select_link_to_Document is called with parameters process_wbook_path and prow

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

Now, that subroutine first of all checks to see if the DocumentFile column of the active row is empty. Actually it's a rather lame way to test emptyness, but it will probably do.

    If Len(Cells(prow, DocumentFile).Value) = 0 Then

And if it is empty then we show a file dialog to obtain a file name:

    Fname = Application.GetOpenFilename("Document Files (*.doc;*.pdf),*.doc;*.pdf", 1, "Select the Document file..")

If a filename has been selected (i.e. the dialog is not cancelled) then we save that file name in the DocumentFile column of the active row for future reference:

    If Fname <> False Then

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

    End If

And that's it!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文