Solved

How to Use OLE To invoke notepad application with a particular text file!

Posted on 1998-11-23
1
783 Views
Last Modified: 2010-10-05
Currently for my application, I am printing the output in a text file.  My intention is when the user clicks on the print command button, it should open up Notepad with that particular text file.  I tried the shell function, but that only opens up notepad.  How do I open that particular text file.  I suppose I have to do this with OLE.  If anybody can help me out with this, I would really appreciate it.
Thanks
0
Comment
Question by:vasant
1 Comment
 
LVL 1

Accepted Solution

by:
Jason_G earned 50 total points
ID: 1446442
Hi Vasant,
You can use the following code to do this, just paste it into the code section of your form;

***Start Of Code***
Private 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

Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Const SW_SHOWNORMAL = 1
 

     'Description:How do I launch a file in its associated program?

Function StartDoc(DocName As String) As Long

       Dim Scr_hDC As Long
       Scr_hDC = GetDesktopWindow()
       StartDoc = ShellExecute(Scr_hDC, "Open", DocName, "", "C:\", SW_SHOWNORMAL)
End Function
 
Private Sub Form_Click()
       Dim r As Long
       r = StartDoc("c:\your_text_file.txt")
       Debug.Print "Return code from Startdoc: "; r
End Sub
***End Of Code***

I hope this helps!

Sincerely,
Jason

Jason Gorman (jason_gorman@scholars.com)
Learning Advisor, http://scholars.com
Microsoft Certified Technical Education Center
Novell Authorized Online Training Provider
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now