[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] [已解决]vbs代码,如何实现:绝对路径修改为相对路径?

本帖最后由 ygqiang 于 2024-7-19 17:50 编辑

[已解决]vbs代码,如何实现:绝对路径修改为相对路径?
vbs文件和2.doc文件,在同一个目录下。c:\test\2.doc修改为2.doc。
2楼代码测试可用。
  1. Option Explicit
  2. Const MSWORD_FILENAME = "c:\test\2.doc"
  3. Sub VBMain()
  4.   Dim wdApp, Doc
  5.   Set wdApp = WSH.CreateObject("Word.Application")
  6.   wdApp.Visible = False
  7.   Set Doc = wdApp.Documents.Open(MSWORD_FILENAME)
  8.   Doc.PrintOut
  9.   Doc.Close
  10.   Set Doc = Nothing
  11.   wdApp.Visible = True
  12.   wdApp.Quit
  13.   Set wdApp = Nothing
  14. End Sub
  15. Call VBMain()
  16. WSH.Quit()
复制代码
  1. currentpath = createobject("Scripting.FileSystemObject").GetFolder(".").Path
  2. MsgBox "当前文件夹是 " & currentpath
复制代码
  1. msgbox "当前文件路径是 " & wscript.ScriptFullName
  2. set ws=CreateObject("WScript.Shell")
  3. MsgBox "当前文件夹是 " & ws.CurrentDirectory
复制代码
  1. Dim fso, scriptPath, currentDrivePath
  2. Set fso = CreateObject("Scripting.FileSystemObject")
  3. scriptPath = WScript.ScriptFullName
  4. currentDrivePath = fso.GetParentFolderName(scriptPath) & "\"
  5. WScript.Echo currentDrivePath
复制代码
1

评分人数

    • Batcher: 感谢给帖子标题标注[已解决]字样PB + 2

本帖最后由 ppll2030 于 2024-7-19 13:09 编辑

你看看这样行不行。改动在第4、5、8这位三行
  1. Option Explicit
  2. Const MSWORD_FILENAME = "2.doc"
  3. Sub VBMain()
  4.   Dim wdApp, Doc, ws
  5.   set ws=CreateObject("WScript.Shell")
  6.   Set wdApp = WSH.CreateObject("Word.Application")
  7.   wdApp.Visible = False
  8.   Set Doc = wdApp.Documents.Open(ws.CurrentDirectory&"\"&MSWORD_FILENAME)
  9.   Doc.PrintOut
  10.   Doc.Close
  11.   Set Doc = Nothing
  12.   wdApp.Visible = True
  13.   wdApp.Quit
  14.   Set wdApp = Nothing
  15. End Sub
  16. Call VBMain()
  17. WSH.Quit()
复制代码
1

评分人数

TOP

你看看这样行不行。改动在第4、5、8这位三行
ppll2030 发表于 2024-7-19 13:07



    谢谢,测试可用。

TOP

返回列表