Here are the Windows API calls for the ShowOpen, ShowSave, ShowPrinter, ShowColor and ShowFont (Thanks to Jaen Saul aka SlowByte for his post) dialogs. Also included is the beginnings of the ShowFonts dialog but I am haning some trouble getting it to work. These calls are more difficult to use than the CommonDialog control placed on a form, but don't have the version conflicts that Early-Bound and Form-Bound ActiveX controls have. In addition, I have added the ability to center the dialog on the form or center it on the screen.
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come
out every day, so no prevention program can catch 100% of them. For your own safety, please:
Re-scan downloaded files using your personal virus checker before using it.
NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
Scan the source code with Minnow's Project Scanner
If you don't have a virus scanner, you can get one at many places on the net
Terms of Agreement:
By using this code, you agree to the following terms...
You may use
this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
You may link to this code from another website, but ONLY if it is not wrapped in a frame.
You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
Nice..could have really used this back when VB 5 had serious version problems with the common dialog OCX. I wrote similar routines, but could never figure out the print dialog. (If this comment was disrespectful, please report it.)
I've looked a bit harder at this code and realized that the print dialog is of no use without the DEVMODE structure. For instance, there doesn't seem to be any way to get the printer oriention from this code. I am now attempting to add the DEVMODE structure to this code, but please report this (or email me) if you have already worked this out.
Kevin, MCP (If this comment was disrespectful, please report it.)
Excellent Point, I have never actually used the Print Dialog API, I only got the code working to the point that it would open the form. If anyone has any more code to put behind the Print Dialog, I'd love to have it. Thanks. (If this comment was disrespectful, please report it.)
You are the third or fourth person to ask me this question, so I figure I'll post it here. When you create a new project, the only default "Reference" that you are able to turn off is "OLE Automation". Evidently, you have turned off "OLE Automation" because it contains the OLE_COLOR definition. (If this comment was disrespectful, please report it.)
When I open file more then 2 file in root dirrectory (multi celect C:\011.txt + C:\022.txt) it's OK and then I open file again but no have anything (open file dialog not show).why ? pease let me know (If this comment was disrespectful, please report it.)
The problem with the Devmode structure for the SHOWPRINTER is documented on MSDN article Q173981. This document does show how to change things such as copies, printer selection, orientation etc and works quite well.
However there is a problem with it. When I use it to send output to my HP Laser 1100i printer, I get a error message "... has performed an illegal operation and has been shutdown".
There is a variation of this document posted on Planet-Source-Code that takes the info in it and turns it into a Class but it fails in the same way.
John (If this comment was disrespectful, please report it.)
IMO, anyone interested in this code should pay a visit to: http://www.vbaccelerator.com/overlib.htm#seclibrary Ther are examples of not just showing the common dialogs, but also hooking them etc... Worth a look (If this comment was disrespectful, please report it.)
Most of the time generic code using the Common Dialog control works for me. I havent had a problem with it yet.
Private Sub mnuPrint_Click() dlgDemo.Flags = 0 dlgDemo.CancelError = True On Error Resume Next dlgDemo.ShowPrinter If Err = 0 Then 'force current default printer: Printer.Orientation = dlgDemo.Orientation
PrinterPrintML txtEdit, 10 Else Err = 0 End If On Error GoTo 0 End Sub
Private Sub mnuPrintSetup_Click() dlgDemo.Flags = cdlPDPrintSetup ' dlgDemo.Flags = cdlPDPageNums dlgDemo.CancelError = False dlgDemo.ShowPrinter End Sub
I would like to know how Can I do when Commond Dialog show the default printer and I change the options of the printer that when I print a document, this document be printed with this options I put in the Commond Dialog.
If you can answer me, please send it me to my e-mail:email@example.com
Thanks for all (If this comment was disrespectful, please report it.)
Very helpful. I could not resolve the dependencies for the ColorDialog on a target machine (worked just fine on the development machine). Kept getting "Run-time error '429': ActiveX component cannot create object". Tried tracking down dependencies, registering OCXs, even running VBC6.EXE. Still kept getting error 429. This code bypassed the whole problem. (If this comment was disrespectful, please report it.)
1/24/2003 7:47:27 AM:
The showprinter can only show the select printer only but it can't really print the the job (If this comment was disrespectful, please report it.)
2/23/2003 12:45:44 PM:
Downloaded (after about 1/2 hour of looking) your .BAS file to incorporate common Open File dialog into a project. Having trouble with preventing user from multi-selecting files. Would rather not let them have the ability to select more than one file, but can't seem to turn off this ability (even after stripping the OFN_ALLOWMULTISELECT flag from the calling button).
Any ideas? Other than that, I think this is excellent code and look forward to incorporating the other dialogs into my other VB projects.
Thanks for a great effort! (If this comment was disrespectful, please report it.)
8/27/2003 8:45:31 AM:
* FOR DISABLE MULTI SELECTING * Delete the line: 'Public Const OFN_ALLOWMULTISELECT = &H200' in the BAS File and all : 'Or OFN_ALLOWMULTISELECT' lines in the project. Good Luck...::) (If this comment was disrespectful, please report it.)
12/17/2003 9:53:52 AM:
Your code does just the job, but I'm having trouble using it in VBA (not VB) - I'm doing it within Excel.
I can't work out how to do the Me.hWnd bit - the Me is a worksheet in Excel.
So close, yet so far! (If this comment was disrespectful, please report it.)
12/17/2003 9:55:05 AM:
Your code is just what I need - but how do I use it in VBA in Excel?
I'm having trouble with the Me.hWnd bit - the Me is an Excel worksheet.
Thanks for any help ... I'm so close yet so far! (If this comment was disrespectful, please report it.)
4/16/2004 3:42:28 AM:
Thanks for your source code. I already downloaded it but i don't understand the API call. I'm having a problem on my assignment on how to use vb 6 to open the Fuji xerox viewer light(program that allowed us to view scanned images). Can you please send me a piece of code on how to open it without using API?
i'm using this code but i seems like not working. The file i selected can't be opened. The selected file doesn't appear on the screen.
hmm, this code looks very similar to the common dialouge stuff in api guide (If this comment was disrespectful, please report it.)
1/26/2005 8:08:41 AM:
hello , I want to close the dialog automatically when it is displayed after pressing a button on a form. The dialog contains ok button ultimaltely the ok button should be pressed automatically is my requirement. Please I need a quick answer. from Raheel (If this comment was disrespectful, please report it.)
1/26/2005 8:12:37 AM:
hi I want some assistance please. I want to close the dialog box automatically which opened after being pressed a button on a form. This dialog contains only ok button. Ultimately this ok button should be pressed automatically. Please I need quick assistance. from Raheel. (If this comment was disrespectful, please report it.)
2/4/2005 1:29:40 PM:
Multiselect does work! in the show open code in the api module change:
If ret Then If Trim$(FileDialog.sFileTitle) = "" Then LastCharacter = 0 Count = 0
If ret Then If Trim$(FileDialog.sFileTitle) = Chr(0) Then LastCharacter = 0 Count = 0 (If this comment was disrespectful, please report it.)
2/8/2005 11:11:39 AM:
Nice code, but in the showsave, you don't care about the sDefaultExt field, so I added the code in the showsave to take care of it
ShowSave.sFiles(1) = Mid(FileDialog.sFile, FileDialog.nFileOffset + 1, InStr(1, FileDialog.sFile, Chr$(0), vbTextCompare) - FileDialog.nFileOffset - 1) FileDialog.sDefFileExt = Trim$(FileDialog.sDefFileExt) If FileDialog.sDefFileExt <> "" Then If Right$(ShowSave.sFiles(1), Len(FileDialog.sDefFileExt)) <> FileDialog.sDefFileExt Then ShowSave.sFiles(1) = ShowSave.sFiles(1) & IIf(InStr(FileDialog.sDefFileExt, ".") > 0, "", ".") & FileDialog.sDefFileExt End If End If
There.... better. (If this comment was disrespectful, please report it.)
thanks (If this comment was disrespectful, please report it.)
Add Your Feedback
Your feedback will be posted below and an email sent to
the author. Please remember that the author was kind enough to
share this with you, so any criticisms must be stated politely, or they
will be deleted. (For feedback not related to this particular code, please
click here instead.)