CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Excel Object

  1. #1
    Join Date
    Aug 1999
    Posts
    45

    Excel Object

    Hi ,
    I want to write to an existing Workbook.
    If the Workbook is open by the time I do Workbook.Save ,
    I'll get error.

    My problem is I don't know how to detect if the Workbook is currently open
    sothat I'll prompt users to close the Workbook before I make changes to it


    Thanks


  2. #2
    Guest

    Re: Excel Object

    Use Spy++ (included in VS 6 Enterprise) to find the Class of Window for Workbook, then use FindWidow API finction. If return is 0, there is no open Workbook, otherwise either give a message or close Workbook using another API PostMessage. For MS Word it looks like this

    Declare Function FindWindow& Lib "user32" Alias "FindWindowA" (byval lpClassName as string, byval lpWindowName as string)
    Declare Function PostMessage& Lib "user32" Alias "PostMessageA" (byval hwnd as Long, byval wMsg as Long, byval wParam as Long, lParam as Any)
    private Const WM_CLOSE = &H10
    Dim lngReturn as Long
    lngReturn = FindWindow("OpusApp", vbNullString)' OpusApp - Window Class for Word
    lngReturn = PostMessage(lngHandle1, WM_CLOSE, 0, 0)



    HTH
    Vlad




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

Featured