how can i open a file from an app?
Printable View
how can i open a file from an app?
A little more detail please. i.e. Open a file for output, input. Open a file that is associated with another app???
like, say i wanted to open the file " andrew.reg" by clicking on a command button
Use the ShellExecute Function
The Code
is
put this in a module
and put this inCode:Public 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
Public Const SW_SHOWNORMAL = 1
your command buttons click function
Code:Call ShellExecute(hwnd, "Open", "c:\andrew.reg", "", "", 1)
be carefull with that file. ShellExecute can open a file with it's associated proggy. In the case of .reg, you might just go and change some reg keys.
td.
cool thanx guys, i got another one thoug, how can i embed a file " andrew.reg" into the program so that it can be ruin on other computers without having to put the specific file in the specific directory?
How did you embed the file into your proggy
I want to do that in one of my progz
if you find the way to do it that is
Does the file contain reg entries?
if so, why not just have the entries in your proggy, and alter the reg from code.
td.
how would i do that?
Depends on what you're trying to set/alter.
VB has some simplistic built in stuff (GetSetting,SaveSetting etc) but you are limited to what/where you can alter - hkey_current_user\software\vb and vba program settings\
If you want to be able to have full control then you have to use some api calls. Look at api calls like RegCreateKey, RegOpenKey etc. Have a search on the API Forum, there's tons of stuff.
td.