本帖最后由 ygqiang 于 2024-7-19 17:50 编辑
[已解决]vbs代码,如何实现:绝对路径修改为相对路径?
vbs文件和2.doc文件,在同一个目录下。c:\test\2.doc修改为2.doc。
2楼代码测试可用。- Option Explicit
- Const MSWORD_FILENAME = "c:\test\2.doc"
- Sub VBMain()
- Dim wdApp, Doc
- Set wdApp = WSH.CreateObject("Word.Application")
- wdApp.Visible = False
- Set Doc = wdApp.Documents.Open(MSWORD_FILENAME)
- Doc.PrintOut
- Doc.Close
- Set Doc = Nothing
- wdApp.Visible = True
- wdApp.Quit
- Set wdApp = Nothing
- End Sub
-
- Call VBMain()
- WSH.Quit()
复制代码
- currentpath = createobject("Scripting.FileSystemObject").GetFolder(".").Path
-
- MsgBox "当前文件夹是 " & currentpath
复制代码
- msgbox "当前文件路径是 " & wscript.ScriptFullName
- set ws=CreateObject("WScript.Shell")
- MsgBox "当前文件夹是 " & ws.CurrentDirectory
复制代码
- Dim fso, scriptPath, currentDrivePath
- Set fso = CreateObject("Scripting.FileSystemObject")
- scriptPath = WScript.ScriptFullName
- currentDrivePath = fso.GetParentFolderName(scriptPath) & "\"
- WScript.Echo currentDrivePath
复制代码
|