2011-03-09 74 views
1

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

回答

5

獲取活動單元格的行號:

prow = ActiveCell.row 

在該行的第1列獲得的價值:

num = Cells(prow, 1).Value 

閱讀活動工作表的名稱(有這裏的錯誤應該是wsheet而不是wshet):

wshet = ActiveSheet.Name 

測試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 

現在,子程序首先檢查,看是否積極行的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 

就是這樣!

+0

非常感謝你..真的幫助我:) – user397316 2011-03-09 22:09:59