Excel VBA用于选择要在其上执行第二个宏的工作簿

时间:2017-03-22 13:32:12

标签: excel-vba vba excel

我从别人的宏中获取此代码。它用于选择我想要执行第二个宏的一组工作簿。我遇到的问题是,如果我选择的文件太多(每个大约3 MB),Excel就会崩溃。我之所以这么认为是因为工作簿存储为Variant而且它使用了太多内存。有一个更好的方法吗?

Sub Import()

    Dim EntryWS As Worksheet
    Dim FPath As String
    Dim ImportFile As Variant
    Dim Continue As Variant

    Set EntryWS = ActiveSheet
    Continue = vbYes
    Do While Continue = vbYes
        ImportFile = Application.GetOpenFilename("Excel Files (*.xls*),*.xls*", 1, "Import File", , True)
        If IsArray(ImportFile) Then
            For Count = LBound(ImportFile) To UBound(ImportFile)
                Call Sales_Success_Import(ImportFile(Count))
            Next Count
        Else: MsgBox Prompt = "No Import File Selected, exiting without importing.", Title = "File Selection Error"
            Exit Sub
        End If
        Continue = MsgBox("Would you like to import another file?", vbYesNo, "Continue Importing")
Loop
    EntryWS.Activate
End Sub

0 个答案:

没有答案