我正在尝试将宏转换成VB脚本,但在'if..then..end‘语句中遇到了问题。这是我的代码。
Option Explicit
Public OpenedWB
Dim valueEntered, fileCount
Dim userResponse
Dim NewWB, NewWS
Dim i
Dim OpenedWBName
Dim Found
Dim FSO, txtFILE
Dim HostFolder
Dim dApproved, dPrepared, filearray()
Dim xlApp
Dim xlCalculationManual
Dim xlCalculationAutomatic, msoFileDialogFolderPicker, msoFileDialogViewSmallIcons
xlCalculationManual = -4135: xlCalculationAutomatic = -4105
msoFileDialogFolderPicker = 4: msoFileDialogViewSmallIcons = 7
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set NewWB = xlApp.Workbooks.Add
NewWB.Windows(1).Visible = True
Set NewWS = NewWB.Worksheets.Add
Set FSO = CreateObject("Scripting.FileSystemObject")
With xlApp
.ScreenUpdating = False
.EnableEvents = False
.Calculation = xlCalculationManual
End With
i = -1
'UI (Dynamic) Directory
With xlApp.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
.Title = "Select the folder to scan through sub-folders"
.ButtonName = "Select this folder!"
.InitialFileName = _
"\\..somepath"
.InitialView = msoFileDialogViewSmallIcons
If .Show <> i Then End 'This is throwing an error (Expected statement error)
HostFolder = .SelectedItems(1)
End With
我不确定为什么我会得到这个错误,因为它在VBA中工作得很好,但我猜这是因为我在VBA子过程中有代码。
有人能帮我解决这个问题吗?
谢谢
发布于 2018-06-09 08:15:00
If .Show <> i Then WScript.Quit
https://stackoverflow.com/questions/50769674
复制相似问题