Solved

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

Posted on 1998-11-23
2
730 Views
Last Modified: 2008-03-10
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
2 Comments
 
LVL 1

Accepted Solution

by:
Jason_G earned 10 total points
ID: 1446443
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
 

Author Comment

by:vasant
ID: 1446444
Well... I actually found the answer for that.  Jason's suggestion was great but there is an easier way to do that.  One can use the shell function to do that as shown below.

  Shell ("notepad.exe c:/temp/Your_file.txt",  vbNormalFocus)

Basically, after the notepad.exe, programmer should give the path to that particular file and then the file name offcourse.

Thanks for your help Jason.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Sending a email via excel using vba 6 96
MsgBox 4 68
How to read File Date Created using VB6 8 50
Collapse and expand table in Word 2010 2 29
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

789 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