Solved

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

Posted on 1998-11-23
2
718 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

708 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

11 Experts available now in Live!

Get 1:1 Help Now