Solved

VBA code to open a Text file from mapped drive

Posted on 2004-09-07
4
374 Views
Last Modified: 2006-11-17
hello experts,
what is the VBA code to open a Text file from a mapped drive?

i am recording receipt Numbers that the user looks at in a flat text file, and i want to have a button on the form that will open that file up in Notepad if the user needs to look at her history.

in otherwords, if the user clicks the button, i want my code to execute Notepad.exe and open up the .txt file on the user's workstation.

thanks,
mac
0
Comment
Question by:MacRena
[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
4 Comments
 
LVL 66

Accepted Solution

by:
Jim Horn earned 100 total points
ID: 12000590
Throw the below two lines of VBA code behind your button.OnClick

Dim dbl As Double
dbl = Shell("c:\windows\notepad.exe {your file.txt}", vbMaximizedFocus)

...where {your file.txt} is the path/file of your text file, without the { }'s.

Hope this helps.
-Jim
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 12000602
To open a specific text file, assuming you have the path in variable strPath and file in strFile:

First paste this into a new module:
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

Now call it with:
ShellExecute hwnd,"open",strFile,Chr$(0),strPath,False
0
 
LVL 4

Author Comment

by:MacRena
ID: 12000827
thanks, Jim.  that was exactly what i was needing.
thanks to you also, shanesuebsahakarn., but i'm going w/ the lesser coding.
mac
0
 

Expert Comment

by:pmcelhany
ID: 12000937
This works for me.  We use the H drive as our personal storage space on our net.
I created a small file(TextDoc.txt) and tried calling it.

    Dim stAppName As String

    stAppName = "C:\Windows\System32\Notepad.EXE H:\TextDoc.txt"
    Call Shell(stAppName, 1)
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

717 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