Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Printing from VB

Posted on 2000-02-18
8
Medium Priority
?
157 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 400 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
Technology Partners: 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

610 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