gpt4 book ai didi

vba - 如果文件扩展名为 .xls,则 MsgBox

转载 作者:行者123 更新时间:2023-12-04 21:37:32 25 4
gpt4 key购买 nike

我编写了一个 VBA 脚本,它为具有大量数据(从 45,000 到 500,000 行)的客户端执行不同的排序/匹配/过滤功能。

问题是,如果用户将此数据导出或另存为 .xls文件,只保存 65,536 行,这可能是不够的。在执行脚本时,我想要一个 MsgBox如果用户“错误地”将数据导出为 .xls,则显示文件,否则继续。

我已经尝试了下面的代码,以查看是否可以正确获取文件扩展名,但是我的 MsgBox没有返回任何东西:

Sub ext()

Dim extFind As String
Dim sFile As String

Dim FilePath As String
FilePath = Application.ActiveWorkbook.Path
sFile = Dir(FilePath & Filename & "*")
extFind = Right$(sFile, Len(sFile) - InStrRev(sFile, "."))
MsgBox extFind
End Sub

任何建议将不胜感激。

最佳答案

FileSystemObject图书馆有一个 GetExtensionName()让生活更轻松的功能:

With CreateObject("Scripting.FileSystemObject")
strExt = .GetExtensionName(ActiveWorkbook.Path)
End With

If StrComp(strExt, "xls", vbTextCompare) = 0 Then
' Display error
End If

或者,您可以只检查工作簿中的行数:
If ActiveSheet.Rows.Count = 65536 Then
' Display error
End If

关于vba - 如果文件扩展名为 .xls,则 MsgBox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31881218/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com