0

我有一个程序,我为此开发了用户指南。我已将此用户指南放在项目目录中。我创建了一个 MenuStrip 项,通过它可以在用户机器上的 Word 中打开用户指南。我成功地使用以下代码做到了这一点:

Try
        userGuide = MSWord.Documents.Open("C:Users\administrator\Documents\VisualStudio2010\Project3\UserGuide.doc")

        MSWord.WindowState = Word.WdWindowState.wdWindowStateNormal
        MSWord.Visible = True
    Catch ex As Exception
        MsgBox("An error has prevented the document from opening. The document may not be available." & vbCrLf & vbCrLf & _
               "Please try one of the following options:" & vbCrLf & _
               "- Check to see if the document is already open" & vbCrLf & _
               "- Restart the program")
    End Try

问题是,用于打开文件的路径在用户机器上不存在。这是一个独立的系统,因此无法创建用于放置文档的文件共享,因此无法编码公共路径。

有没有办法编写动态路径?也许是这样的:

userGuide = MSWord.Documents.Open("%windir%\UserGuide.doc")

谢谢!

4

1 回答 1

1

如果文档将相对于应用程序可执行文件的安装路径存储,则从exe 的路径开始:

Dim path As String
path = System.IO.Path.GetDirectoryName( _
      System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)

Dim docPath as String;

docPath = Path.Combine(path,"UserGuide.doc");
于 2012-05-27T04:05:23.667 回答