Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Print form from other application

Good morning --

I want to print out a blank form (probably a pdf) from another application,
then have the user reload that form into the printer and have Excel fill it
out. I want to do it that way because it's a lot easier than designing the
10-page form in Excel, and it's a government form and I want them to accept
it.

So I'll have a MsgBox that says, "You're going to print out the right pdf
form." Then I want the pdf form to print. It will be in the same directory
as the Excel workbook.

If the form is called "855B.pdf", can anyone help me with the command to
print it out?

Thanks in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 128
Default Print form from other application

On Jun 17, 11:21 am, pdberger
wrote:
Good morning --

I want to print out a blank form (probably a pdf) from another application,
then have the user reload that form into the printer and have Excel fill it
out. I want to do it that way because it's a lot easier than designing the
10-page form in Excel, and it's a government form and I want them to accept
it.

So I'll have a MsgBox that says, "You're going to print out the right pdf
form." Then I want the pdf form to print. It will be in the same directory
as the Excel workbook.

If the form is called "855B.pdf", can anyone help me with the command to
print it out?

Thanks in advance.


Hello pdberger,

This macro will print the PDF file you specify. By using the Windows
API, you don't need to know which version of Acrobat Reader the user
has or where it is on their system. After add ing a Standard VBA
Module to your project, copy and paste the macro code into it.

Example of calling the macro:
PrintDoc "855B.pdf"
If the file is not in the current directory you need to include the
full directory path.

'Begin Macro Code
'Written: June 18, 2007
'Author: Leith Ross
'Summary: Print any document that is has a registered file extension

Option Explicit

Private Declare Function ShellExecute _
Lib "shell32.dll" _
Alias "ShellExecuteA" _
(ByVal hwnd As Long, _
ByVal lpszOp As String, _
ByVal lpszFile As String, _
ByVal lpszParams As String, _
ByVal lpszDir As String, _
ByVal FsShowCmd As Long) As Long

Private Declare Function GetDesktopWindow Lib "user32" () As Long

' Show Window Constants
Const SW_HIDE = 0&
Const SW_NORMAL = 1&
Const SW_SHOWMINIMIZED = 2&
Const SW_SHOWMAXIMIZED = 3&
Const SW_SHOWNOACTIVATE = 4&
Const SW_SHOW = 5&
Const SW_MINIMIZE = 6&
Const SW_SHOWMINNOACTIVE = 7&
Const SW_SHOWNA = 8&
Const SW_RESTORE = 9&
Const SW_SHOWDEFAULT = 10&

' Error Code Constants
Const SE_ERR_FNF = 2&
Const SE_ERR_PNF = 3&
Const SE_ERR_ACCESSDENIED = 5&
Const SE_ERR_OOM = 8&
Const SE_ERR_DLLNOTFOUND = 32&
Const SE_ERR_SHARE = 26&
Const SE_ERR_ASSOCINCOMPLETE = 27&
Const SE_ERR_DDETIMEOUT = 28&
Const SE_ERR_DDEFAIL = 29&
Const SE_ERR_DDEBUSY = 30&
Const SE_ERR_NOASSOC = 31&
Const ERROR_BAD_FORMAT = 11&

Public Sub PrintDoc(DocName As String)

Dim hDesktop As Long
Dim ShellRet As Long

hDesktop = GetDesktopWindow()
ShellRet = ShellExecute(hDesktop, "Print", DocName, "", "",
SW_NORMAL)

If ShellRet < 33 Then Call PrintError(ShellRet)

End Sub

Private Sub PrintError(ShellRet As Long)

Dim Msg As String

Select Case ShellRet
Case SE_ERR_FNF
Msg = "File not found"
Case SE_ERR_PNF
Msg = "Path not found"
Case SE_ERR_ACCESSDENIED
Msg = "Access denied"
Case SE_ERR_OOM
Msg = "Out of memory"
Case SE_ERR_DLLNOTFOUND
Msg = "DLL not found"
Case SE_ERR_SHARE
Msg = "A sharing violation occurred"
Case SE_ERR_ASSOCINCOMPLETE
Msg = "Incomplete or invalid file association"
Case SE_ERR_DDETIMEOUT
Msg = "DDE Time out"
Case SE_ERR_DDEFAIL
Msg = "DDE transaction failed"
Case SE_ERR_DDEBUSY
Msg = "DDE busy"
Case SE_ERR_NOASSOC
Msg = "No association for file extension"
Case ERROR_BAD_FORMAT
Msg = "Invalid EXE file or error in EXE image"
Case Else
Msg = "An unknown error occurred"
End Select

MsgBox Msg, vbCritical, "Print File"

End Sub
'End Macro Code

Sincerely,
Leith Ross

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
New form of application.run SteveDB1 Excel Programming 10 June 9th 07 12:29 AM
nice input application form יונתן Charts and Charting in Excel 0 July 4th 06 03:49 PM
Open Form (VBA Running) and Application.OnTime Ronald Dodge Excel Programming 1 December 16th 05 02:41 PM
Can I make an order form on an office application? Michelle Excel Discussion (Misc queries) 2 August 24th 05 12:14 AM
Display form from an VB application in Excel kuhni Excel Discussion (Misc queries) 0 August 10th 05 06:04 PM


All times are GMT +1. The time now is 09:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"