Solved

VB.NET SendKeys ... File Open window

Posted on 2011-03-23
6
959 Views
Last Modified: 2012-05-11
I have a VB.NET application that I am writing.  I need to capture a file by the user and feed that filename into the "file open" of another application.  I am simulating it in this example with notepad.  

The code works until it comes to populating the "open" window in notepad.  

I have tried SendKeys.Send and SendKeys.SendWait

NOTE:  The application (i.e. NOTEPAD) will already be open.

- - - - sample code excerpt - - - -
            openFD.ShowDialog()
            AppActivate("untitled - notepad")
            SendKeys.SendWait("%FO")
           
            ' All is well until this next line.  This line does not work
            SendKeys.SendWait("{quote}" & openFD.FileName & "{quote}{enter}")
0
Comment
Question by:javajws
  • 3
6 Comments
 
LVL 20

Accepted Solution

by:
darbid73 earned 500 total points
ID: 35197219
Whenever I see send keys I always think - is this really the only way to do it.  It is arguable that sendkeys is not realiable.

If I understand you correctly the user is going to use the windows dialog to open a file.  You would like to intercept or listen to this process and get the file that is being opened and use that information somewhere else?
0
 
LVL 9

Author Comment

by:javajws
ID: 35197354
My program will ask the user for the filename with the Windows dialog to open a file.  That filename (and path) will not be opened, it will be used to copy the file from the network folder to a local folder and open the local file in another program (for now, Notepad).  

I have the first part working.  It asks for a file, copies the file from the network path to the local path.  I am then able to locate the application (in this case Notepad) using "AppActive".  

Now I want to simulate "File...Open" and feed the path/filename, to open the user requested file.
0
 
LVL 20

Expert Comment

by:darbid73
ID: 35197401
Ok so you have the full path name to the file which is now saved locally.

Your example (which I know is an example) is with notpad.

I would use something like this
System.Diagnostics.Process.Start("notepad.exe", "mydocument.txt")

Open in new window


Why do you need to imitate how a user opens it?

What is the program you really want to open the file in?
0
 
LVL 20

Expert Comment

by:darbid73
ID: 35496317
The questioner wants to open a file with, in this example notepad.

His example has been answered and one could assume satisfactorily, as he has not questioned it or asked for more assistance for more than a month.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

828 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