Excelmacros – 可以解释这个吗?
我是新的Excelmacros。
任何人都可以告诉我这个macros是什么?
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
获取活动单元格的行号:
prow = ActiveCell.row
获取该行第1列中的值:
num = Cells(prow, 1).Value
阅读活动工作表的名称(这里有一个错误,应阅读wsheet
而不是wshet
):
wshet = ActiveSheet.Name
testingnum
是否大于0,单元格A4包含“#”,活动工作表等于名为People_wsheet
的variables或常量。 如果是这样,一个名为people_select_link_to_Document
的子例程被调用,参数process_wbook_path
和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
现在,该子程序首先检查活动行的DocumentFile
列是否为空。 其实这是一个相当蹩脚的方式来testing空虚,但它可能会做。
If Len(Cells(prow, DocumentFile).Value) = 0 Then
如果它是空的,那么我们显示一个文件对话框来获得一个文件名:
Fname = Application.GetOpenFilename("Document Files (*.doc;*.pdf),*.doc;*.pdf", 1, "Select the Document file..")
如果select了一个文件名(即对话框没有被取消),那么我们将该文件名保存在活动行的DocumentFile
列中以供将来参考:
If Fname <> False Then Cells(prow, DocumentFile).Value = Fname 'global path End If
而就是这样!