编了一个程序,弄了一个帮助文档"help.doc"
想通过单击事件打开这个word文档,因为是要交给老师的,所以要用相对路径,请问各位VB高手,怎么实现它?
希望论坛上的各位高手能够帮助一下小弟。

解决方案 »

  1.   

    把文档放在执行文件同目录下,然后打开路径设置为:app.path & "\help.doc"就可以了
      

  2.   

    我刚开始是这么写的,但好像不行Private Sub help_Click()
    Shell (App.Path + "\1.DOC")
    End Sub关于shell这个函数我们学的不多,希望大侠们指教了。
      

  3.   

    二楼说的那个好像没用吧,我到百度查了一下,shell好像只可以打开*.exe,*.dat之类的文件吧…
      

  4.   

    刚才试了一下,在本地这样可以:
    Shell "C:\Program Files\Microsoft Office\office11\winword.exe   D:\我的文档\大作业\help.doc", 1
    请问,怎么改为相对路径啊?
    求助啊,今天就要交作业了啊!
      

  5.   

    shell "C:\Program Files\Microsoft Office\office11\winword.exe " & App.Path & "\help.doc"
      

  6.   

    但那个word程序一定会装在那个目录下么?
      

  7.   

    你要把两个不确定放在一起的话用shell是解决不了,只有在工程里创建Word对象(或引用Word),然后再打开了,网上有很多例子自己找找就知道了
      

  8.   

    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    Private Sub Form_Load()
    ShellExecute Me.hwnd, "open", App.Path & "\1.doc", vbNullString, vbNullString, SW_SHOWNORMAL
    Me.Hide
    End Sub
      

  9.   

    答老张:
    是help.doc,其实这不是主要问题。你写的东西有点复杂,对于我这个初学者有一些难度,你能不能按我下面的格式重新写一下代码,十分感谢!Private Sub help_Click()
    Shell "C:\Program Files\Microsoft Office\office11\winword.exe   D:\我的文档\大作业\help.doc", 1
    End Sub
      

  10.   

    Option   Explicit   
      Private   Declare   Function   ShellExecute   Lib   "shell32.dll"   Alias   "ShellExecuteA"   (ByVal   hwnd   As   Long,   ByVal   lpOperation   As   String,   ByVal   lpFile   As   String,   ByVal   lpParameters   As   String,   ByVal   lpDirectory   As   String,   ByVal   nShowCmd   As   Long)   As   Long   
        
      Private   Sub   Command1_Click()   
              Dim   file   As   String   
              file   =   "help.doc"   
              ShellExecute   0,   "open",   file,   vbNullString,   vbNullString,   5   
      End   Sub   
      

  11.   

    Option  Explicit  
      Private  Declare  Function  ShellExecute  Lib  "shell32.dll"  Alias  "ShellExecuteA"  (ByVal  hwnd  As  Long,  ByVal  lpOperation  As  String,  ByVal  lpFile  As  String,  ByVal  lpParameters  As  String,  ByVal  lpDirectory  As  String,  ByVal  nShowCmd  As  Long)  As  Long  这句话具体啥意思我不知道,但它在编译时出现了错误,说在“End sub,End function或End 属性后面只能出现注释”,能不能给我写一段直接可以用的代码啊?拜托各位大侠了……
      

  12.   

    你就新建一个工程,将我的代码拷入,App.Path & "\1.doc"就是doc文件路径,App.Path是指doc文件要和VB工程保存在一起,属相对路径,用绝对路径也可,如将App.Path & "\1.doc"改为"D:\我的文档\大作业\help.doc" ,一样的,shell不好用.
      

  13.   


    谢谢,感觉你是个高手,^-^
    但是这两个工程怎么联系起来啊,我想通过单击来触发这个动作,可不可以这样想(恕我愚昧):
    Private Sub help_Click()
    工程2.Form1.Show (刚才试了好像不行)
    End Sub工程2的代码(按你写的):
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    Private Sub Form_Load()
    ShellExecute Me.hwnd, "open", App.Path & "\help.doc", vbNullString, vbNullString, SW_SHOWNORMAL
    Me.Hide
    End Sub是这样理解么?
      

  14.   

    '单击打开
    Private Sub help_Click()
    ShellExecute Me.hwnd, "open", App.Path & "\help.doc", vbNullString, vbNullString, SW_SHOWNORMAL 
    Me.Hide 
    End Sub 
      

  15.   

    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long 
    -----这个拷过来没有?拷过来放在最上边.
      

  16.   

    上面的代码没问题。
    你创建一个文件夹(文件夹名任取),在其中新建一个Word文件(取名help.doc),打开vb6.0,新建"工程1"(保存时一定要与help.doc放在同一文件夹内),将上面的代码复制到form1中去,并在该窗体上添加一个"Command1"。好了,就这么简单。
      

  17.   

    word放在目录下,但具体语句就不是很清楚了。
      

  18.   

    先引用OFFICE-WORD  DLL
    Dim wordApp As New Word.Application
    Dim wordDoc As New Word.Document
    Set wordApp = CreateObject("Word.Application") '½¨Á¢WORDʵÀý
    wordApp.Visible = False 'ÆÁ±ÎWORDʵÀý´°Ìå
    Set wordDoc = wordApp.Documents.Open(FileName) '´ò¿ªÎļþ²¢¸³ÓèÎļþʵÀý
      

  19.   

    http://download.csdn.net/source/1627134