Results 1 to 12 of 12

Thread: CreateObject starts but what ends???

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2000
    Posts
    16

    Question

    I have a vb program that opens a word.basic file and puts in a lot of formatted information. What I would like to do, is allow vb to END and let the user close word when they are finished printing or editing or whatever. OR---in my vb code, know when the user has closed word, then let me close vb.

  2. #2
    Addicted Member
    Join Date
    Sep 2000
    Location
    Atlanta, GA
    Posts
    177

    Talking

    After you are finish with the object. set it to nothing.
    212 will lead you to the truth

  3. #3
    Junior Member
    Join Date
    Oct 2000
    Location
    High Wycombe, UK
    Posts
    25

    re CreateObject

    Set object = nothing
    Ciao.........Gary

    VB6, SQL Server 7, Access 97

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Oct 2000
    Posts
    16

    Nothing stops word

    I don't think my problem is clear....

    The user controls when Word is done. My vb program cannot close word. I want to close my VB program and leave word running.

  5. #5
    Addicted Member
    Join Date
    Sep 2000
    Location
    Atlanta, GA
    Posts
    177
    Simply place:

    Unload Me

    After your last line of the coding that activates Word
    212 will lead you to the truth

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Oct 2000
    Posts
    16

    Unhappy Unload ME stops word TOO

    Sorry Doc, but Unload ME stops word as well.

    My last lines of code are:

    MyWord.FilePrintPreview
    Unload me
    end sub


  7. #7
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722
    Try using shell to open word, instead of instantiating it. I haven't tried it yet, though

    r0ach™
    Don't forget to rate the post

  8. #8
    Member
    Join Date
    Sep 2000
    Location
    The Netherlands
    Posts
    42

    Question How about ShellExecute???

    I don't know if you put things in the Word document interactively from VB. If not, why not use ShellExecute to lauch Word with the right file?

    Greets,
    Greetings,

    Hajo Dijkstra


  9. #9

    Thread Starter
    Junior Member
    Join Date
    Oct 2000
    Posts
    16

    VB is building the Word document

    In my application, I am reading a text file and selectively putting information into the word document from VB, so SHELL won't work for me.

  10. #10
    Member
    Join Date
    Sep 2000
    Location
    The Netherlands
    Posts
    42

    Question Edit and shell?

    How about first using Word through CreateObject.
    Modify the document with your data from the text file
    and then save it. This all can be done without Word being
    visible, so the user can not interupt this process. After
    saving the file, close Word (the CreateObject version) and
    use ShellExecute to launch Word/the file so it will exist
    after your application is closed.

    Hope this helps you.

    Greetings,
    Greetings,

    Hajo Dijkstra


  11. #11
    Addicted Member
    Join Date
    Sep 2000
    Posts
    138
    I wrote the following in my vb application to test whether the user has closed an application (Word, Excel, Pbrush, etc.). It has worked well so far. I hope it may help.(Reply to the latter part of your post.)

    Put it in a module. (I copied it directly from my app.)

    Code:
    -------------------------------------------
    Private Declare Function GetWindow Lib "user32" (ByVal _
    hwnd As Long, ByVal wCmd As Long) As Long

    Private Declare Function GetDesktopWindow Lib "user32" () _
    As Long

    Private Declare Function GetWindowText Lib "user32" Alias _
    "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString _
    As String, ByVal cch As Long) As Long

    Private Const GW_HWNDFIRST = 0
    Private Const GW_HWNDLAST = 1
    Private Const GW_HWNDNEXT = 2
    Private Const GW_HWNDPREV = 3
    Private Const GW_OWNER = 4
    Private Const GW_CHILD = 5

    Public Function CheckApp(ByVal AppCaption As String) As Long
    '
    '--------------------------------------------------------------
    ' Check whether an application has been closed.
    ' Return:0 = Not Closed; 1 = Closed
    ¡® It¡¯s better to use the VB keyword Like in the IF statement.
    ¡® AppCaption is the first few characters of the name of a window, whether shown or hidden.
    '--------------------------------------------------------------
    Dim lngHwnd As Long
    Dim strWinText As String
    Dim lngCch As Long
    Dim lngReturn As Long

    lngHwnd = GetDesktopWindow()
    lngHwnd = GetWindow(lngHwnd, GW_CHILD)
    Do
    lngCch = 255
    strWinText = String(255, 0)
    lngReturn = GetWindowText(lngHwnd, strWinText, lngCch)
    strWinText = Left(strWinText, lngReturn)
    If Left(strWinText, Len(AppCaption)) = AppCaption Then
    CheckApp = 0
    Exit Do
    End If
    CheckApp = 1
    lngHwnd = GetWindow(lngHwnd, GW_HWNDNEXT)
    Loop Until lngHwnd = 0

    End Function

    -----------------------------------------
    Visual Basic Professional 6.0


  12. #12

    Thread Starter
    Junior Member
    Join Date
    Oct 2000
    Posts
    16

    Smile IT works - Thanks XMIN

    Sorry for the slow response, but I was out of the office. Got this information from XMIN and put it into my program and it is working great. Thanks for all of the help!! Mr_Ed

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