Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2007
    Posts
    348

    Unanswered: Opening Word from Access

    I have someone who would like to make regular, automated changed to a word doc. I was going to use the hyperlink property and OpenHyperlink method to open it. I did not realize he wanted to keep the document password protected as well.
    Can anyone point me in a direction to Open a word doc and pass it the password, do my thing, then close it back up?

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    This is air code but it is about right....

    Code:
    Dim oW as new Word.Application
    oW.Visible = True
     
    Dim oD as Word.Document
     
    Set oD = oW.Documents.Open "C:\MyDoc.doc", , , "MyPassword"
    Need a reference to the Word object library of course. Or you can late bind.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Feb 2007
    Posts
    348
    Thanks pootle, you are always a big help.
    I searched the web and looked in my books and couldn't find it.

  4. #4
    Join Date
    Jun 2007
    Location
    Maitland NSW,Australia
    Posts
    388

    Opening Word

    I use the following to open a word document

    Sub release_notes()
    On Error GoTo Err_release_notes

    Dim app_name As String
    Dim file_location As String

    file_location = "c:\databases\release_notes.doc"

    app_name = "c:\program files\microsoft office\office\winword.exe " & file_location

    Call Shell(app_name, 1)

    Exit_release_notes:
    Exit Sub

    Err_release_notes:
    MsgBox Err.Description
    Resume Exit_release_notes
    End Sub

    Depending of the version of access you may have to change office to office11.

  5. #5
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Depends what you want to do. Using shell you can't provide the password. Also if you want to actually do anything with the application (i.e. automate it) you need an object reference. It is perfectly fine if you just need to open it. I tend to use the object approach only because then I don't need to remember two lots of syntax (shell for opening, object for opening & subsequently doing stuff).
    Testimonial:
    pootle flump
    ur codings are working excelent.

  6. #6
    Join Date
    Feb 2007
    Posts
    348
    Pootle,
    I have a dumb question, I hate to even ask. How did you know this? I've looked at the MSDN online I've googled the word object library but I haven't found what you were able to know. I'm mostly looking for a reference, a book or website. Something I can use to up my knowledge without having to ask each and every question here.

    This was the best reference I have found and it makes doesn't mention the password thing:
    http://support.microsoft.com/kb/q184974/

  7. #7
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Well, a little experience and a little knowledge.

    If you are automating another office application you know you need to access that application's object library. So I went into word, launched VBA and then help. I searched for "open" and "document" and eventually found a section on Opening a Document. The code was simply:
    Code:
    Sub OpenDocument()
        Documents.Open FileName:="C:\MyFolder\Sample.doc"
    End Sub
    Documents is a collection and Open is a method. One thing that comes with experience is knowing this could be rewritten
    Code:
    Application.Documents.Open FileName:="C:\MyFolder\Sample.doc"
    In the same way, "Application" is optional in Acces before DoCmd and Forms etc.. The Application is optional because it is assumed that you are referring to the Application object of the application that you are running the code in. As such, you need to explicitly create an object to reference the automated application in your calling code (which is why the Dim oW as new Word.Application bit is required).
    Anyway, I looked up the Documents collection, searched the methods for Open and found the exact syntax.

    Nothing magic or clever
    Testimonial:
    pootle flump
    ur codings are working excelent.

  8. #8
    Join Date
    Feb 2007
    Posts
    348
    Quote Originally Posted by pootle flump
    Well, a little experience and a little knowledge.
    That much I know to be true but there are some paths that are better and quicker than others. Usually after I get an answer from you all, I try to reverse engineer the answer. I run it through Help or Google and see what comes out and look into the further implications. I was really surprised that after having the answer, I was having trouble dredging up more info.

    Quote Originally Posted by pootle flump
    If you are automating another office application you know you need to access that application's object library. So I went into word, launched VBA and then help.
    Ah, now that is the nugget I am hunting for. That little piece of info has a lot of mileage behind it.

    Quote Originally Posted by pootle flump
    Nothing magic or clever
    Oh sure, next thing you'll tell me is that there isn't a Santa Claus. I don't think I could stand that :-)

Posting Permissions

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