使用带有if / else语句的复选框的输入框调用函数

时间:2019-10-07 05:28:03

标签: excel vba

所以我有2个函数,我想要一个也有一个复选框的输入框,以便我可以运行if / else语句。

我尝试使用用户表单,但是我不太了解如何正确使用它们。

我想使用

之类的东西
If checkbox = True
   Call GetSubFiles
else 
   call GetAllFiles
end if

(甚至不知道这样是否可以使用其伪代码)

我要调用的2个函数是

Sub GetAllFiles()


Dim objFSO As Scripting.FileSystemObject
Dim objFolder As Scripting.Folder
Dim Path As Variant

Path = InputBox("Enter filepath")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Path)

ActiveWorkbook.ActiveSheet.Cells.Clear

With Range("A1", "H1")
    .Interior.Color = RGB(12, 2, 120)
    .Value = "Table of Contents"
    .Font.Bold = True
    .Font.Size = .Font.Size + 3
    .Font.Color = RGB(255, 255, 255)
End With

Range("A1").Value = "Directory"
Range("B1").Value = "File Name"
Range("C1").Value = "Size KB"
Range("D1").Value = "Date Created"
Range("E1").Value = "Date Last Modified"
Range("F1").Value = "Date Last Accessed"
Range("G1").Value = "Path Length"
Range("H1").Value = "File Type"

Call GetFileDetails(objFolder)

End Sub

如果未单击复选框

Sub GetSubFiles()

ActiveWorkbook.ActiveSheet.Cells.Clear

With Range("A1", "H1")
    .Interior.Color = RGB(12, 2, 120)
    .Value = "Table of Contents"
    .Font.Bold = True
    .Font.Size = .Font.Size + 3
    .Font.Color = RGB(255, 255, 255)
End With

Range("A1").Value = "Directory"
Range("B1").Value = "File Name"
Range("C1").Value = "Size KB"
Range("D1").Value = "Date Created"
Range("E1").Value = "Date Last Modified"
Range("F1").Value = "Date Last Accessed"
Range("G1").Value = "Path Length"
Range("H1").Value = "File Type"

Call listSubFiles

End Sub

如果选中该复选框

此输入框必须能够使用文件路径的字符串 以及用于确定是否必须列出子文件夹的内容或仅列出子文件夹本身的复选框的正确或错误

0 个答案:

没有答案