• Chart Window

    Author
    Topic
    #357090

    Hi all,

    Today I noticed something I had not noticed before when I right clicked a chart in Excel 2000 – the Chart Window. I can get this to display in it’s own window, which I can move around and so forth, but I cannot seem to find where to access any of the properties of this window, such as getting it to remain on top. Whenever I click out of the window, it disappears. Any ideas out there?

    Thanks,

    Viewing 0 reply threads
    Author
    Replies
    • #529786

      Mike,

      I think you have discovered most of the properties of the chart window yourself. When you activate a chart contained in a ChartObject, the chart actually is contained in a window that is normally invisible. By right-clicking the ChartObject and select Chart Window from the shortcut menu, you can see the embedded chart in its own window. You can move and resize this window (but you can’t maximize it). However, the embedded chart will still be displayed in its origianl location. As soon as you activate another window, you make the chart window invisible again.

      When an embedded chart’s window is visible, you can print the chart by right-clicking its title bar and selecting Print from the shortcut menu. Then your embedded chart will be printed on a full page by itself (just as if it were a chart on a chart sheet), still remaining an embedded chart.

      Selecting the embedded chart, then via File >> Print you will be able to print the embedded chart too.

      If you want to print all embedded charts on a worksheet using a macro, then it would be better to make the window visible, print the chart and make the window invisible after printing.

      • #529791

        Thanks Hans,

        What I was trying to do was get the chart window to remain on top, visible, so that the user could see it change as they changed the data. I may play around with a selection change event to make the chart window visible again.

        Thanks,

        • #529803

          Mike,

          I think you have to use an API call to do that. Here you have some code that puts a userform always on top. You can change it to have your chart window (use the appropriate caption) always on top. The code below activates a userform and in the userform_activate event, the window is put always on top, using a subroutine that uses an API call. Use this and replace the UserForm1.Caption with the title of your chart window. I think this should work (although I did not try it out).

          Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
          (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
          
          Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, _
          ByVal hwndinsertafter As Long, ByVal x As Long, _
          ByVal y As Long, ByVal cx As Long, ByVal cy As Long, _
          ByVal wflags As Long) As Long
           Sub set_on_top(hdl As Variant, bTop As Boolean)
           Const SWP_NOSIZE = &H1
           Const SWP_NOMOVE = &H2
           Const SWP_NOACTIVATE = &H10
           Const SWP_SHOWWINDOW = &H40
           Const HWND_TOPMOST = -1
           Const HWND_NOTOPMOST = -2
           Dim WinFlags As Variant
           Dim PosFlag As Variant
           Dim return_code As Long
           WinFlags = SWP_NOMOVE Or SWP_NOSIZE Or SWP_SHOWWINDOW Or SWP_NOACTIVATE
           Select Case bTop
             Case True
               PosFlag = HWND_TOPMOST
             Case False
               PosFlag = HWND_NOTOPMOST
           End Select
           return_code = SetWindowPos(hdl, PosFlag, 0, 0, 0, 0, WinFlags)
           End Sub
          
          Sub startFrlm()
          UserForm1.Show
          End Sub
          

          And you have to add some code for the userform:

          Private Sub CmdExit_Click()
          Unload Me
          End Sub
          
          Private Sub UserForm_Activate()
          Dim handle As Long
          handle = FindWindow("ThunderDFrame", UserForm1.Caption)
          Call set_on_top(handle, True)
          End Sub
          

          There is only one problem with this code: the “ThunderDFrame” class name is only valid for userforms in Excel 2000. I must admit not to know the class name for chart windows. I just add what I do know: XLMAIN is the class name for Excel’s main window, EXCEL7 is the class name for an Excel Worksheet and bosa_sdm_xl9 is the class name for an Excel dialog sheet (I don’t know if chart windows are contained in this last class). Please don’t shoot the messenger, where this bosa_sdm_xl9 comes from, ask Microsoft…

          Anyhow, I am very interested to know if you get this working and what the class name of a chart window might be…

          • #529808

            Hi Hans,

            geez ….. where do you pull these snippets from? If you say Paris is in California or Norway for that matter….I believe you!

            Anyway, will try this and post the results here.

            Thanks,

    Viewing 0 reply threads
    Reply To: Chart Window

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: