I need to print a PDF file from within my VB application, so what kind of code do I need attached to my command button OnClick event? (I am assuming that the computer already has the Adobe Reader program installed — if not, I need a graceful way back to my VB form.
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Printing a PDF from VB (VB 6.0 / W98)
Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Printing a PDF from VB (VB 6.0 / W98)
- This topic has 7 replies, 2 voices, and was last updated 22 years, 10 months ago.
AuthorTopicWSChuck Tucker
AskWoody LoungerAugust 7, 2002 at 7:52 pm #374673Viewing 0 reply threadsAuthorReplies-
WSKevin
AskWoody LoungerAugust 7, 2002 at 8:04 pm #606811The best way to do this is to first check to see if the file association is in place. If so, Reader is installed. Use the FindExecutable API function for that.
Next, use the ShellExecute API function with the “Print” operation (parameter 2).You can also reference the pdf.ocx/tlb library and use it’s property SRC to name the file and the method Print to print the pdf.
I like the ShellExecute technique better.
p.s. the pdf.ocx has no documentation except what you can find via google, etc., and it is quiet unstable (at least on W2k).
Search this forum for more discussion on the pdf.ocx control.
-
WSChuck Tucker
AskWoody LoungerAugust 7, 2002 at 10:17 pm #606847Hi Kevin,
Thanks for the advice. I got the first part working great – it detects the presence of the Acrobat Reader. If not, I change my command button caption to “you need to install Acrobat Reader.”
However, being a novice at VB 6, I am struggling with exactly how to call the ShellExecut function to print the file.
I have this so far, but I immediately get a “expected expression” error message.
Call ShellEx(hwnd,”Print”,”C:Program FilesAPI VisionInstructions.PDF”,NULL,,)
I kind of expected it to go off and print the file.
(Frankly, I really don’t understand the “hwnd” part.)
-
WSKevin
AskWoody LoungerAugust 7, 2002 at 10:33 pm #606851The ShellExecute function needs a window handle as the first parameter so it knows where to return any errors. Use the current window (your app, a userform, the desktop, etc.). To get the current window handle, use GetActiveWindow
hWnd = GetActiveWindow() — Dim hWnd as long
The function expects all five parameters and you are missing one.
Throw these values at the function:
hWnd (you’re fine here if you get a valid window handle); “Print” (you absolutely nailed this one), the filename (full path as you have done), 0& (that’s zero ampersand — something about a directory), 0& (another of the same — a paramaters parameter) and last but not least: 1 — the Show parameter. 1 says show normal which I think means don’t show the app, in this case Acrobat Reader.
Call ShellEx(hwnd,”Print”,”C:Program FilesAPI VisionInstructions.PDF”,0&,0&,1)
-
WSChuck Tucker
AskWoody LoungerAugust 7, 2002 at 11:10 pm #606861Hi again,
I’ll be darned if it didn’t work perfectly! But, of course, that’s never the end of it.
I notice that upon finishing printing I’m left with the Adobe Acrobat task running (minimized on the Task Bar). Is there some way to detect that it is done and kill the Acrobat task?
Thanks once more, you have been very gracious with your help.
-
WSKevin
AskWoody LoungerAugust 8, 2002 at 4:01 pm #607096Chuck,
If it leaves Acrobat running it didn’t work perfectly! Ha! You should not have to bother with killing the process. Acrobat should load (in the background — you should not see the splash screen, print the file and exit. That’s how it works here.
Is this what your API declaration looks like:
Public Declare Function ShellExecute Lib “shell32.dll” Alias “ShellExecuteA” _
(ByVal hWnd As Long, ByVal lpOperation _
As String, ByVal lpFile As String, ByVal _
lpParameters As String, ByVal lpDirectory _
As String, ByVal nShowCmd As Long) As Long -
WSChuck Tucker
AskWoody Lounger -
WSKevin
AskWoody Lounger
-
-
-
-
Viewing 0 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
McLaren Health Care says data breach impacts 743,000 patients
by
Nibbled To Death By Ducks
3 minutes ago -
WhatsApp banned on House staffers’ devices
by
Alex5723
1 hour, 18 minutes ago -
Is your device eligible?
by
Susan Bradley
3 hours, 2 minutes ago -
Windows 11 Insider Preview build 26200.5661 released to DEV
by
joep517
9 hours, 13 minutes ago -
Windows 11 Insider Preview build 26120.4452 (24H2) released to BETA
by
joep517
9 hours, 15 minutes ago -
Hello Windows…My Problem is Windows Hello…
by
rdleib
10 hours, 30 minutes ago -
New Canon Printer Wants Data Sent
by
Win7and10
10 hours, 48 minutes ago -
I set up passkeys for my Microsoft account
by
Lance Whitney
18 minutes ago -
AI is for everyone
by
Peter Deegan
10 hours, 21 minutes ago -
Terabyte update 2025
by
Will Fastie
4 hours, 24 minutes ago -
Migrating from Windows 10 to Windows 11
by
Susan Bradley
5 hours, 25 minutes ago -
Lost sound after the upgrade to 24H2?
by
Susan Bradley
1 day, 9 hours ago -
How to move 10GB of data in C:\ProgramData\Package Cache ?
by
Alex5723
7 hours, 3 minutes ago -
Plugged in 24-7
by
CWBillow
19 hours, 32 minutes ago -
Netflix, Apple, BofA websites hijacked with fake help-desk numbers
by
Nibbled To Death By Ducks
1 day, 22 hours ago -
Have Copilot there but not taking over the screen in Word
by
CWBillow
1 day, 19 hours ago -
Windows 11 blocks Chrome 137.0.7151.68, 137.0.7151.69
by
Alex5723
3 days, 13 hours ago -
Are Macs immune?
by
Susan Bradley
5 hours, 23 minutes ago -
HP Envy and the Function keys
by
CWBillow
2 days, 21 hours ago -
Microsoft : Removal of unwanted drivers from Windows Update
by
Alex5723
14 hours, 53 minutes ago -
MacOS 26 beta 1 dropped support for Firewire 400/800
by
Alex5723
4 days, 1 hour ago -
Unable to update to version 22h2
by
04om
1 day, 9 hours ago -
Windows 11 Insider Preview Build 26100.4482 (24H2) released to Release Preview
by
joep517
4 days, 8 hours ago -
Windows 11 Insider Preview build 27881 released to Canary
by
joep517
4 days, 8 hours ago -
Very Quarrelsome Taskbar!
by
CWBillow
3 days, 18 hours ago -
Move OneNote Notebook OFF OneDrive and make it local
by
CWBillow
4 days, 21 hours ago -
Microsoft 365 to block file access via legacy auth protocols by default
by
Alex5723
4 days, 10 hours ago -
Is your battery draining?
by
Susan Bradley
16 hours, 31 minutes ago -
The 16-billion-record data breach that no one’s ever heard of
by
Alex5723
1 day, 10 hours ago -
Weasel Words Rule Too Many Data Breach Notifications
by
Nibbled To Death By Ducks
5 days, 1 hour ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.