Solved

Printing from VB

Posted on 2000-02-18
8
147 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
  • 5
  • 2
8 Comments
 
LVL 14

Expert Comment

by:mcrider
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 14

Expert Comment

by:mcrider
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:aacosta
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now