Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 21st, 2004, 01:49 PM
Registered User
 
Join Date: Sep 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Can I send a command to print a txt file from Excl

Hi Everyone,

That's for the help in the past.

Can I send a command to print a txt file from Excel?

Please send an example!

Thanks!:)

K Moran
 
Old October 27th, 2004, 05:17 AM
Authorized User
 
Join Date: Aug 2004
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This method uses notepad. It is possible to print using the DOS command window, but it gives problems if you use a network printer.

The code may need tweaking - might need full path references to Notepad, and change the Wait statement for a big file so there is plenty of time for this to happen before the next line of code tries to run.
Code:
Sub test()
    Dim MyFile As String
    Dim Enterkey As String
    Dim Alt As String
    Dim RetVal As Variant
    '----------------------
    MyFile = "C:\TEST.TXT"
    Enterkey = "~"
    Alt = "%"
    '- open file in notepad
    RetVal = Shell("notepad.exe" & " " & MyFile, vbNormalFocus)
    If RetVal = 0 Then
        MsgBox ("Problem opening Notepad.")
        End
    End If
    '- send keystrokes to print
    SendKeys Alt & "FP", True
    '- wait 2 seconds for print to happen
    Application.Wait Now + TimeValue("00:00:02")
    '- close notepad
    SendKeys Alt & "{F4}", True
End Sub

-----------------------
Regards BrianB
Most problems occur from starting at the wrong place.
Use a cup of coffee to make Windows run faster.
It is easy until you know how.





Similar Threads
Thread Thread Starter Forum Replies Last Post
USING Command Button to print Worksheet alannoble Excel VBA 2 December 31st, 2004 11:17 AM
How to enable the print command in the File menu? wslstarnite Visual C++ 1 August 30th, 2004 01:45 PM
How to enable print command in the File Menu? wslstarnite BOOK: Beginning Visual C++ 6 1 August 30th, 2004 01:19 PM
VB Printer.print command Hiddenattractor Java GUI 3 December 30th, 2003 09:08 AM
Command Button to Print in Landscape Orientation brlevy Access 3 June 9th, 2003 11:59 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.