Results 1 to 9 of 9

Thread: Using Word 2000 in VB 6 [RESOLVED]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2003
    Location
    Chicago, IL
    Posts
    102

    Using Word 2000 in VB 6 [RESOLVED]

    I have a form that will be used to open an existing Word document. I have that functionality working... sort of. Here's the code snippet...

    'Using Reference to Microsoft Word 9.0 Object Library

    Dim oleWordApp As Word.Application
    Dim oleWordPath As Word.Document

    Private Sub cmdOpen_Click()
    Set oleWordApp = CreateObject("Word.Application")
    Set oleWordPath = oleWordApp.Documents.Open("\\cody\safety procedures\SECTION 01 SAFETY AND LOSS PREVENTION PROGRAM REV. B.DOC")
    End Sub

    Private Sub Form_Unload(Cancel As Integer)
    frmMain.Show
    Set oleWordApp = Nothing
    Set oleWordPath = Nothing
    End Sub

    This opens the document, but not before requiring notification or opening as Read-Only. I'm sure that can be taken care of in the other options that are part of the Open function. A couple of questions:

    1) What are the acceptable values to give for the other options in the Open function? (ConfirmConversions, ReadOnly, AddtoRecentFiles, PasswordDocument, PasswordTemplate, Revert, WritePasswordDocument, WritePasswordTemplate, Format, Encoding, and Visible) I tried VBYes and VBNo, but it didn't like that.

    2) What values are returned when the user presses Notify, ReadOnly, or Cancel? I need to be able to handle the doc if the user presses Cancel. This question can be negated if I can get the above working.

    Thanks in advance!
    Last edited by Daywalker46410; Aug 26th, 2003 at 05:15 PM.
    Joe Cody
    Data Integration Engineer
    Novaspect, Inc.
    Elk Grove Village, IL

  2. #2
    Fanatic Member
    Join Date
    Jun 2003
    Location
    IL
    Posts
    739
    Can't you just do, before trying to open it up?

    oleWordApp.DisplayAlerts = wdAlertsNone

    Then you won't get any notification at all.
    Motto: Anything for a laugh.

    Getting second place only means you are the first loser to cross the finish line.

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    For the readonly under the open method use True or False instead.
    The intellisense usually shows the type for you.
    Try something like - .Open("C:\Test.doc", False, False, vbNullString, etc.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2003
    Location
    Chicago, IL
    Posts
    102
    Neither of the above worked. I modified the code to appear like this:

    Dim oleWordApp As Word.Application
    Dim oleWordPath As Word.Document

    Private Sub cmdOpen_Click()
    Set oleWordApp = CreateObject("Word.Application")
    oleWordApp.DisplayAlerts = wdAlertsNone
    Set oleWordPath = oleWordApp.Documents.Open("\\cody\safety procedures\SECTION 01 SAFETY AND LOSS PREVENTION PROGRAM REV. B.DOC", False, False)

    End Sub
    Private Sub Form_Unload(Cancel As Integer)
    frmMain.Show
    End Sub

    But I still get a message that the file is open with an option to open read only, notify when free, or cancel. And if I select cancel, the program errors out due to "Operation Failed." Having the program open as read only is OK for the viewing part of the app, but I can't display that message; my users are too "special" to respond accordingly. Plus I need to be able to edit the document in another section.
    Joe Cody
    Data Integration Engineer
    Novaspect, Inc.
    Elk Grove Village, IL

  5. #5
    Fanatic Member
    Join Date
    Jun 2003
    Location
    IL
    Posts
    739
    Can't you make a copy of the file and then open up the copy? This way no one will have it open.
    Motto: Anything for a laugh.

    Getting second place only means you are the first loser to cross the finish line.

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Here is some help from the help file. Note the bolded part.



    expression.Open(FileName, ConfirmConversions, ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate, Revert, WritePasswordDocument, WritePasswordTemplate, Format, Encoding, Visible, OpenConflictDocument, OpenAndRepair , DocumentDirection, NoEncodingDialog)

    expression Required. An expression that returns a Documents object.

    FileName Required Variant. The name of the document (paths are accepted).

    ConfirmConversions Optional Variant. True to display the Convert File dialog box if the file isn't in Microsoft Word format.

    ReadOnly Optional Variant. True to open the document as read-only. Note This argument doesn't override the read-only recommended setting on a saved document. For example, if a document has been saved with read-only recommended turned on, setting the ReadOnly argument to False will not cause the file to be opened as read/write.

    AddToRecentFiles Optional Variant. True to add the file name to the list of recently used files at the bottom of the File menu.

    PasswordDocument Optional Variant. The password for opening the document.

    PasswordTemplate Optional Variant. The password for opening the template.

    Revert Optional Variant. Controls what happens if FileName is the name of an open document. True to discard any unsaved changes to the open document and reopen the file. False to activate the open document.

    WritePasswordDocument Optional Variant. The password for saving changes to the document.

    WritePasswordTemplate Optional Variant. The password for saving changes to the template.

    Format Optional Variant. The file converter to be used to open the document. Can be one of the following WdOpenFormat constants.

    WdOpenFormat can be one of these WdOpenFormat constants.
    wdOpenFormatAllWord
    wdOpenFormatAuto The default value.
    wdOpenFormatDocument
    wdOpenFormatEncodedText
    wdOpenFormatRTF
    wdOpenFormatTemplate
    wdOpenFormatText
    wdOpenFormatUnicodeText
    wdOpenFormatWebPages

    To specify an external file format, apply the OpenFormat property to a FileConverter object to determine the value to use with this argument.

    Encoding Optional Variant. The document encoding (code page or character set) to be used by Microsoft Word when you view the saved document. Can be any valid MsoEncoding constant. For the list of valid MsoEncoding constants, see the Object Browser in the Visual Basic Editor. The default value is the system code page.

    Visible Optional Variant. True if the document is opened in a visible window. The default value is True.

    OpenConflictDocument Optional Variant. Specifies whether to open the conflict file for a document with an offline conflict.

    OpenAndRepair Optional Variant. True to repair the document to prevent document corruption.

    DocumentDirection Optional WdDocumentDirection. Indicates the horizontal flow of text in a document.

    WdDocumentDirection can be one of these WdDocumentDirection constants.
    wdLeftToRight default
    wdRightToLeft

    NoEncodingDialog Optional Variant. True to skip displaying the Encoding dialog box that Word displays if the text encoding cannot be recognized. The default value is False.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Aug 2003
    Location
    Chicago, IL
    Posts
    102
    Well, I figured out why it was being listed as in use. When I clicked the button the first time, it created the object alright and, apparently, opened it up, but I couldn't see it. I found a couple of instances of WINWORD.EXE in the processes. I added a "oleWordApp.Visible" statement after the Open statement and it worked fine. Plus I was able to use the exact same code, but added a "False" to the second flag for Open (Read Only) and it opens a nice Read Only version of the file. Thanks for everyone's help!
    Joe Cody
    Data Integration Engineer
    Novaspect, Inc.
    Elk Grove Village, IL

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    The multiple instances or Word are from debugging in vb. If you
    stop the project without the code closing the document or the
    Word application that will happen.

    It happens on any of the Office applications.

    Glad to hear its working.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774
    as a matter of good practice I always create a Close_stuff sub which I call at the begining and end of any sequence dealling with objects (like word). This sub has the useuall set obj=nothing, and obj.close stuff this means that I don't ever get extra objects filling up the memory.

    I tend to call this On Error if I plan to quit the sub I'm in.

    I also like to call it not in the sub that opens the objects but in the sub that calls the opening sub so that regardless of when it exits it then closes all objects.

    does that make sense? Sometimes these structured approaches to programming seem real anal but there is a point to it all I assure you.

    (Edit: Spot the typos )
    Last edited by Matt_T_hat; Sep 12th, 2003 at 04:29 AM.
    ?
    'What's this bit for anyway?
    For Jono

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