Excel 宏 - 谁能解释一下?
我是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
获取活动单元格的行号:
获取该行第1列的值:
读取活动工作表的名称(这里有一个错误,应该读取
wsheet
而不是wshet< /code>):
测试
num
是否大于 0,并且单元格 A4 包含“#”,并且活动工作表是否等于名为People_wsheet
的变量或常量。如果是这样,则使用参数process_wbook_path
和prow
调用名为people_select_link_to_Document
的子例程。现在,该子例程首先检查
活动行的 >DocumentFile
列为空。实际上,这是一种相当蹩脚的测试空性的方法,但它可能会起作用。如果它是空的,那么我们将显示一个文件对话框来获取文件名:
如果已选择文件名(即对话框未取消),那么我们将该文件名保存在文件的
DocumentFile
列中。活动行以供将来参考:就是这样!
Get the row number of the active cell:
Get the value in column 1 of that row:
Read the name of the active worksheet (there is an error here, should read
wsheet
rather thanwshet
):Test if
num
is greater than 0, and the cell A4 contains "#" and the active worksheet is equal to a variable or constant calledPeople_wsheet
. And if so, a subroutine calledpeople_select_link_to_Document
is called with parametersprocess_wbook_path
andprow
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.And if it is empty then we show a file dialog to obtain a file name:
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:And that's it!