Results 1 to 19 of 19

Thread: open word file

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    122

    Resolved open word file

    hello,
    i tried using these codes

    Dim objWord As Word.Application
    Set objWord = New Word.Application
    objWord.Visible = True
    objWord.Documents.Open " & App.Path & \HelpFile.doc"

    to open a word file but it doesnt seem to work?
    will appreciate any help.
    thanks.
    Last edited by binbpk; Sep 7th, 2007 at 11:58 PM.

  2. #2
    Hyperactive Member
    Join Date
    Jul 2007
    Location
     
    Posts
    453

    Re: open word file

    Why dont you just use the insertable control for word documents?
    Haikus are easy.
    But sometimes they don't make sense.
    Refrigerator.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    122

    Re: open word file

    err is that for vb6?

  4. #4
    Hyperactive Member
    Join Date
    Jul 2007
    Location
     
    Posts
    453

    Re: open word file

    yup, goto the project menu, click components, click insertable objects, there should be a ms word one there I think...
    Haikus are easy.
    But sometimes they don't make sense.
    Refrigerator.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    122

    Re: open word file

    how do i drop this on the mdi form?

  6. #6
    Hyperactive Member
    Join Date
    Jul 2007
    Location
     
    Posts
    453

    Re: open word file

    well, you cont put it on the mdi form, mdi forms can only have toolbars, etc. you will have to put it on the main mdi child which you just draw it on there, like you would anything else...
    Haikus are easy.
    But sometimes they don't make sense.
    Refrigerator.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    122

    Re: open word file

    this actually works when i put in C:....
    i think there must be something wrong with the other lines in here:
    objWord.Documents.Open " & App.Path & \HelpFile.doc"

    how do you write it when you want your application to be able to open a file regardless of where its placed in?

  8. #8
    Hyperactive Member
    Join Date
    Jul 2007
    Location
     
    Posts
    453

    Re: open word file

    I cant help you with that, I have no Idea...
    Haikus are easy.
    But sometimes they don't make sense.
    Refrigerator.

  9. #9
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: open word file

    It's better to use ShellExecute if you want to open a document in the program that reads that document type.
    Code:
    Private Declare Function GetDesktopWindow Lib "user32" () As Long
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
    
    Public Function RunFile(pstrFile As String, Optional ByVal pstrDefaultFolder As String) As Long
        Const SW_SHOW = 1
        Dim lngPos As Long
        Dim lngDesktop As Long
        
        If Len(pstrDefaultFolder) = 0 Then
            lngPos = InStrRev(pstrFile, "\")
            If lngPos > 0 Then pstrDefaultFolder = Left$(pstrFile, lngPos - 1)
        End If
        lngDesktop = GetDesktopWindow()
        RunFile = ShellExecute(lngDesktop, "Open", pstrFile, "", pstrDefaultFolder, SW_SHOW)
    End Function
    Sample usage:

    RunFile App.Path & "\HelpFile.doc"

    Note that this works for any document type; not just word. It is the code equivalent to double-clicking a file from an explorer window.

  10. #10
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: open word file

    try this line before the open:
    msgbox App.Path & \HelpFile.doc"
    looks to me like a simple error (assuming you copied it correctly)
    should be app.path & "\helpfile.doc"

    people always overlook the obvious...
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    122

    Re: open word file

    i tried this but it still does not work.

    objWord.Documents.Open App.Path & "\HelpFile.doc"

  12. #12
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: open word file

    show us what your app.path is. It may already have the \ on the end for example. Also you will annoyingly get different results for app.path depending on whether the program is compiled or not.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  13. #13
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: open word file

    try
    objWord.Documents.Add App.Path & "\HelpFile.doc"
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    122

    Re: open word file

    Quote Originally Posted by westconn1
    try
    objWord.Documents.Add App.Path & "\HelpFile.doc"
    nope, still doesnt work. could it be because i'm using word 2007?
    it says user defined type not defined.
    Last edited by binbpk; Sep 7th, 2007 at 11:40 PM.

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    122

    Re: open word file

    Quote Originally Posted by Lord Orwell
    show us what your app.path is. It may already have the \ on the end for example. Also you will annoyingly get different results for app.path depending on whether the program is compiled or not.
    it's in my documents folder so it reads:
    C:\Documents and Settings\User\My Documents\College\Applied Communication Technology\Assignment\CPMS

  16. #16
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: open word file

    so that's what you saw when you did a msgbox(app.path) or what you think it should be?
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  17. #17
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: open word file

    try pasting in the full path
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  18. #18

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    122

    Re: open word file

    Quote Originally Posted by Lord Orwell
    so that's what you saw when you did a msgbox(app.path) or what you think it should be?
    you mean it's supposed to read the path to my documents folder?

  19. #19

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    122

    Re: open word file

    ok managed to get it to work. i did not select the word object library from the references.
    thank you so much for all your help.
    appreciate it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width