?
Solved

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

Posted on 1998-11-23
2
Medium Priority
?
755 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
Jason_G earned 40 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…
Suggested Courses
Course of the Month11 days, 20 hours left to enroll

752 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