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.
![]() |
There are isolated problems with current patches, but they are well-known and documented on this site. |
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, 9 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
-
No more rounded corners??
by
CWBillow
2 hours, 13 minutes ago -
Android 15 and IPV6
by
Win7and10
54 minutes ago -
KB5058405 might fail to install with recovery error 0xc0000098 in ACPI.sys
by
Susan Bradley
12 hours, 9 minutes ago -
T-Mobile’s T-Life App has a “Screen Recording Tool” Turned on
by
Alex5723
14 hours, 51 minutes ago -
Windows 11 Insider Preview Build 26100.4202 (24H2) released to Release Preview
by
joep517
9 hours, 26 minutes ago -
Windows Update orchestration platform to update all software
by
Alex5723
22 hours, 10 minutes ago -
May preview updates
by
Susan Bradley
9 hours, 33 minutes ago -
Microsoft releases KB5061977 Windows 11 24H2, Server 2025 emergency out of band
by
Alex5723
1 hour, 9 minutes ago -
Just got this pop-up page while browsing
by
Alex5723
14 hours, 22 minutes ago -
KB5058379 / KB 5061768 Failures
by
crown
11 hours, 26 minutes ago -
Windows 10 23H2 Good to Update to ?
by
jkitc
46 minutes ago -
At last – installation of 24H2
by
Botswana12
1 day, 13 hours ago -
MS-DEFCON 4: As good as it gets
by
Susan Bradley
44 minutes ago -
RyTuneX optimize Windows 10/11 tool
by
Alex5723
2 days, 1 hour ago -
Can I just update from Win11 22H2 to 23H2?
by
Dave Easley
20 minutes ago -
Limited account permission error related to Windows Update
by
gtd12345
2 days, 15 hours ago -
Another test post
by
gtd12345
2 days, 15 hours ago -
Connect to someone else computer
by
wadeer
2 days, 9 hours ago -
Limit on User names?
by
CWBillow
2 days, 13 hours ago -
Choose the right apps for traveling
by
Peter Deegan
2 days, 2 hours ago -
BitLocker rears its head
by
Susan Bradley
1 day, 10 hours ago -
Who are you? (2025 edition)
by
Will Fastie
1 day, 9 hours ago -
AskWoody at the computer museum, round two
by
Will Fastie
2 days, 5 hours ago -
A smarter, simpler Firefox address bar
by
Alex5723
3 days, 1 hour ago -
Woody
by
Scott
3 days, 11 hours ago -
24H2 has suppressed my favoured spider
by
Davidhs
1 day, 10 hours ago -
GeForce RTX 5060 in certain motherboards could experience blank screens
by
Alex5723
4 days, 1 hour ago -
MS Office 365 Home on MAC
by
MickIver
3 days, 19 hours ago -
Google’s Veo3 video generator. Before you ask: yes, everything is AI here
by
Alex5723
4 days, 15 hours ago -
Flash Drive Eject Error for Still In Use
by
J9438
1 day, 10 hours 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.