标题: [文本处理] [已解决]vbs代码,如何实现:绝对路径修改为相对路径? [打印本页]
作者: ygqiang 时间: 2024-7-19 10:29 标题: [已解决]vbs代码,如何实现:绝对路径修改为相对路径?
本帖最后由 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
复制代码
作者: ppll2030 时间: 2024-7-19 13:07
本帖最后由 ppll2030 于 2024-7-19 13:09 编辑
你看看这样行不行。改动在第4、5、8这位三行- Option Explicit
- Const MSWORD_FILENAME = "2.doc"
- Sub VBMain()
- Dim wdApp, Doc, ws
- set ws=CreateObject("WScript.Shell")
- Set wdApp = WSH.CreateObject("Word.Application")
- wdApp.Visible = False
- Set Doc = wdApp.Documents.Open(ws.CurrentDirectory&"\"&MSWORD_FILENAME)
- Doc.PrintOut
- Doc.Close
- Set Doc = Nothing
- wdApp.Visible = True
- wdApp.Quit
- Set wdApp = Nothing
- End Sub
-
- Call VBMain()
- WSH.Quit()
复制代码
作者: ygqiang 时间: 2024-7-19 17:49
你看看这样行不行。改动在第4、5、8这位三行
ppll2030 发表于 2024-7-19 13:07
谢谢,测试可用。
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |