XL97: Using the Common Dialog (Print) Control Flags Property

Last reviewed: February 27, 1998
Article ID: Q170698
The information in this article applies to:
  • Microsoft Excel 97 for Windows

SUMMARY

The Flags property for the CommonDialog control is used to return or set options in CommonDialog control dialog boxes. Most settings in the dialog boxes are related to a constant that can be used to set or return the value of the Flags property. This article contains an example that uses the Flags property to set and return several options in the CommonDialog control (in this case, the Print dialog box).

MORE INFORMATION

Microsoft provides examples of Visual Basic for Applications procedures for illustration only, without warranty either expressed or implied, including, but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

The following steps assume you installed the ActiveX controls from the Microsoft Office 97 Office Developer Edition (ODE); the CommonDialog control is not installed when you install Microsoft Office 97.

Setting Options in the Print Dialog Box

To use the Flags property to set options in the Print dialog box, follow these steps:

  1. Save and close all open workbooks, and then create a new workbook.

  2. Start the Visual Basic Editor.

  3. On the Insert menu, click UserForm.

  4. If the CommonDialog control is not displayed in the Toolbox, click Additional Controls on the Tools menu. Click "Microsoft Common Dialog Control, version 5.0" in the Additional Controls dialog box, and then click OK.

  5. Place a copy of the CommonDialog control on the UserForm, and then place a CommandButton on the UserForm.

  6. Double-click the CommandButton to display the module behind the UserForm, and then enter the following code for the Click event of the CommandButton:

          Private Sub CommandButton1_Click()
    

          CommonDialog1.Flags = cdlPDDisablePrintToFile + cdlPDNoSelection
          CommonDialog1.ShowPrinter
    

          End Sub
    

  7. Run the UserForm, and then click the CommandButton when the UserForm is displayed.

    The Print dialog box is displayed. The Print To file check box is cleared, and the Selection option is not selected.

  8. Click OK, and then close the UserForm.

Returning User Options from the Print Dialog Box

To continue the project in the previous section and return user options from the Print dialog box, follow these steps:

  1. Change the code for the click event of the CommandButton to the following:

          Private Sub CommandButton1_Click()
    

          CommonDialog1.ShowPrinter
    

          ' The statement "CommonDialog1.Flags And cdlPDPrintToFile" has a
          ' value of 0 when the Print To file check box is not selected and
          ' a value of 32 when it is selected.
          MsgBox CommonDialog1.Flags And cdlPDPrintToFile
    

          End Sub
    

  2. Run the UserForm, and then click the CommandButton when the UserForm is displayed.

  3. Click the Print To File check box, and then click OK.

    A message box displays a value of 32. This is the decimal equivalent of Hexadecimal 20, the value of the cdlPDPrintToFile constant.

  4. Click OK to close the message box.

  5. Click the CommandButton again and clear the Print To File check box when the Print dialog box is displayed.

  6. Click OK to close the Print dialog box.

    A message box displays a value of 0, which indicates that the Print To File check box was not selected.

  7. Click OK to close the message box.

  8. Close the UserForm.

The constants that are available for the Flags property are listed in the following table.

   Constant                 Value    Description
   ----------------------------------------------------------------------

   cdlPDAllPages            &H0      Returns or sets the state of the All
                                     Pages option button.

   cdlPDCollate             &H10     Returns or sets the state of the
                                     Collate check box.

   cdlPDDisablePrintToFile  &H80000  Disables the Print To File check box.

   cdlPDHelpButton          &H800    Causes the dialog box to display the
                                     Help button.

   cdlPDHidePrintToFile     &H100000 Hides the Print To File check box.

   cdlPDNoPageNums          &H8      Disables the Pages option button and
                                     the associated edit control.

   cdlPDNoSelection         &H4      Disables the Selection option button.

   cdlPDNoWarning           &H80     Prevents a warning message from being
                                     displayed when there is no default
                                     printer.

   cdlPDPageNums            &H2      Returns or sets the state of the Pages
                                     option button.

   cdlPDPrintSetup          &H40     Causes the system to display the Print
                                     Setup dialog box rather than the Print
                                     dialog box.

   cdlPDPrintToFile         &H20     Returns or sets the state of the Print
                                     To File check box.

   cdlPDReturnDC            &H100    Returns a device context for the
                                     printer selection made in the dialog
                                     box. The device context is returned
                                     in the dialog box's hDC property.

   cdlPDReturnDefault       &H400    Returns default printer name.

   cdlPDReturnIC            &H200    Returns an information context for the
                                     printer selection made in the dialog
                                     box. An information context provides a
                                     fast way to get information about the
                                     device without creating a device
                                     context. The information context is
                                     returned in the dialog box's hDC
                                     property.

   cdlPDSelection           &H1      Returns or sets the state of the
                                     Selection option button. If neither
                                     cdlPDPageNums nor cdlPDSelection is
                                     specified, the All option button is in
                                     the selected state.

   cdlPDUseDevModeCopies    &H40000  If a printer driver doesn't support
                                     multiple copies, setting this flag
                                     disables the Number of copies spinner
                                     control in the Print dialog. If a
                                     driver does support multiple copies,
                                     setting this flag indicates that the
                                     dialog box stores the requested number
                                     of copies in the Copies property.

REFERENCES

For more information about the Flag property, click the Index tab in Visual Basic for Applications Help, type the following text

   flags

and then double-click the selected text to go to the "Flags Property (Print Dialog)" topic.


Additional query words: XL97
Keywords : kbcode kbprg
Version : WINDOWS:97
Platform : WINDOWS
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 27, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.