我已经问了一个问题来搜索2个位置的文件然后打开它,Xbier回答了我的问题并给了我脚本但它显示编译错误我不知道如何解决这个问题,
Sub foo2()
Set fso = CreateObject("Scripting.FileSystemObject")
Set shl = CreateObject("WScript.Shell")`enter code here`
Path = "C:\Program Files (x86)\SAP\FrontEnd\SAPgui\" 'path to folder
exists = fso.FolderExists(Path)
If (exists) Then
program = "saplogon.exe" 'Program name to run
shl.Run (Path & program) 'Run a program
Else
Path = "C:\Program Files\SAP\FrontEnd\SAPgui\"
program = "saplogon.exe" 'Program name to run
shl.Run (Path & program) 'Run a program
End If
Set sapConn = CreateObject("SAP.Functions") 'Create ActiveX object
sapConn.Connection.ApplicationServer = "C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe"
sapConn.Connection.Client = "100" ' only read access
End Sub
答案 0 :(得分:0)
将代码移出ThisWorkbook
的代码模块,并将其放入标准代码模块中。
ThisWorkbook.Path
是只读属性,无法通过代码进行修改。
如果出于某些奇怪的原因,您需要代码成为ThisWorbook
代码模块的一部分,请使用不属于{{1}的属性的变量名称对象。