vba - 预期语句结束 vba 程序
问题描述
我正在尝试将 excel 文件从不同的文件夹复制到保存/存在此脚本的文件夹中。我在下面的代码中收到“预期语句结束”错误,有人可以帮忙吗?
Option Explicit
Dim FSO
Dim sFile As String
Dim sSFolder As String
Dim sDFolder
Dim anObject As Object
sFile = "Filename.xlsm"
sSFolder = "C:\workspace"
Set FSO = CreateObject("Scripting.FileSystemObject")
sDFolder = FSO.GetAbsolutePathName("C:\")
If Not FSO.FileExists(sSFolder & sFile) Then
MsgBox "Specified File Not Found", vbInformation, "Not Found"
Else
FSO.CopyFile (sSFolder & sFile), sDFolder, True
End If
解决方案
未经测试,但您不能使用 VBA 代码而不将其分段为子过程。您应该用 开始一个语句Sub (your subname)
并用 结束它End Sub
。见下文。
Option Explicit
Sub MyCode
Dim FSO
Dim sFile As String
Dim sSFolder As String
Dim sDFolder
Dim anObject As Object
sFile = "Filename.xlsm"
sSFolder = "C:\workspace"
Set FSO = CreateObject("Scripting.FileSystemObject")
sDFolder = FSO.GetAbsolutePathName("C:\")
If Not FSO.FileExists(sSFolder & sFile) Then
MsgBox "Specified File Not Found", vbInformation, "Not Found"
Else
FSO.CopyFile (sSFolder & sFile), sDFolder, True
End If
End Sub
推荐阅读
- google-sheets - 只有在一列中有公共数据(名称)时,如何在多个电子表格之间复制信息?
- html - 为什么我的 CSS 网格列在我的导航上不起作用?
- c# - 单个 Select() 语句或多个用于多步骤转换的语句?
- javascript - 无法使用 Ant Design 禁用 Step(动态)
- mongodb - MongoDB C# 驱动程序的 DistinctAsync 引发无法反序列化“列表”
'来自 BsonType '字符串' - python - Python tkinter 减少路径但作为完整目录打开
- azure - AKS 在从 ACR 中提取容器映像时出现问题
- r - 基于先前观察的新变量
- macros - 如何使用 gensym 符号捕获宏变量?
- android - 如何在 Kotlin Andorid 中读取 Apollo 客户端响应/GraphQL 响应的响应数据