首页 > 解决方案 > 如何在不映射目标文件夹的情况下在服务器上打开 pdf 文件?

问题描述

我使用 Shell 命令打开物理上位于服务器上的 pdf 文件。该命令工作正常,因为我的计算机上映射了一个目标文件夹。我要做的是在没有映射文件夹的情况下打开文件。如果可能的话,我很难理清思绪?

这是我使用的一段代码:

Sub open_file()   
VBA.Shell "Explorer.exe \\servername\Documents\2021\2\3\new_document.pdf", vbNormalFocus
End Sub

标签: vba

解决方案


Sub open_file()   
  Dim wsh
  Set wsh = CreateObject("WScript.Shell")
  'if path contains spaces it should be enclosed in quotes
  'error handling required (path doesn't exist, pdf application isn't installed, etc.)
  wsh.Run "\\servername\Documents\2021\2\3\new_document.pdf"
End Sub

推荐阅读