Solved

Printing from VB

Posted on 2000-02-18
8
151 Views
Last Modified: 2010-05-02
Hi,
  I am interested in a program that will check files into a directory and print their files.
  The problem is that I don´t know how to check a file (for example .doc) and print it automaticly. Is it posible?.

  Can you tell me how to do it or point me somewhere?.

Thks!.

Alejandro Acosta A.
0
Comment
Question by:aacosta
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 14

Expert Comment

by:mcrider
ID: 2536030
See the microsoft KB article:

HOWTO: Use ShellExecute to Launch Associated File (32-bit)
http://support.microsoft.com/support/kb/articles/Q170/9/18.asp?LNG=ENG&SA=MSDN&FR=1 


In the example you will see the line:

   StartDoc = ShellExecute(Scr_hDC, "Open", DocName, _
          "", "C:\", SW_SHOWNORMAL)
     

If you change the "Open" to "Print" in this line, it will print the document to the default printer using the native application that the file belongs to.  For example, a .DOC file is associated with Word.  This will print the document through word...


Cheers!
0
 
LVL 14

Accepted Solution

by:
mcrider earned 100 total points
ID: 2536064
By the way, if you dont want to have the application visible, you would change that line to:

   StartDoc = ShellExecute(Scr_hDC, "Print", DocName, _
          "", "C:\", 0)



Cheers!
0
 
LVL 6

Expert Comment

by:Marine
ID: 2536105
Its going to be a few more lines then mcrider proposed. Yes you would need to use ShellExecute to print this but to check files you would need something else. I'll see if i can find something for you to solve this. Can i do something like this. Put all the listed files from a directory into a FileList control and then when you click on that file you will print it is that good enough ?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:mcrider
ID: 2536184
I am assuming that aacosta knows how to select the files that are to be printed...  The problem was actually PRINTING the files...

If that was too big of an assumption, I'm sorry...

There are so many ways to select a file(s)...  It all depends on what you want your interface to look like.

You can use the CommonDialog control to select the file(s)...

You can use the DriveListbox DirListbox and FileListbox to select the drive/directory/file...

You can use the Dir statement to get the files in a directory...


All of these are WELL DOCUMENTED in the VB Help file.


aacosta, If you need any more information, let me know.



Cheers!

0
 
LVL 1

Author Comment

by:aacosta
ID: 2536225
Hi again.
  The document at http://support.microsoft.com/support/kb/articles/Q170/9/18.asp?LNG=ENG&SA=MSDN&FR=1 was great!. I already used the code and work great.

  Can you tell me in addition how to get the files that are into a directory?.

Thanks.

0
 
LVL 14

Expert Comment

by:mcrider
ID: 2536286
aacosta,

Thanks for the points! Glad I could help...

In my previous comment I mention several ways to get files... Do you have any idea which method you want to use?? (CommonDialog, FileListBoxes, or the DIR Statement??)


Cheers!
0
 
LVL 1

Author Comment

by:aacosta
ID: 2536404
I think dir Statement is ok.

I would like to print all the files that are into a directory and then move them to another directory. What is the best way?.

I dont want you to do my Job, I just need a help.

Thanks again :-)
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2536451
This code will show all of the files in the directory c:\windows\desktop to the debug window...

    Dim lFileName As String
    lFileName = Dir("c:\windows\desktop\*.*")
    Do While Not lFileName = ""
        Debug.Print lFileName
        lFileName = Dir()
    Loop


To move the files, you can use the FileCopy statement to copy the files to where you want it to go and then use the Kill statement to delete the original file...


Cheers!

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question