Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Every process runs with a current default directory (folder). This folder is used for file operations if you don't specify another folder. You can view the name of the default directory with the CurDir function: Sub AAA() Debug.Print CurDir End Sub When working only on the local drives, you can use the ChDir function for changing the current directory to another (existing) folder: Sub AAA() ChDir "C:\Test\This" End Sub However, you cannot use ChDir to set the current directory to a folder using a UNC or network file name. It won't cause an error but it won't do anything. Sub AAA() ' This does not work.... ChDir "\\SecurityJoan\MainShare\Test" End Sub The Windows API function SetCurrentDirectory works with UNC names. E.g., Sub AAA() SetCurrentDirectoryA "\\Aja\MainShare\Test" End Sub The ChrDirNet sub that you refer to simply calls SetCurrentDirectoryA. If you need SetCurrentDirectoryA, there is no reason to wrap it up in another sub such as your ChDirNet sub. You can call SetCurrentDirectoryA directly. Windows itself is composed of dozens of DLL files which are, basically, libraries of functions that both Windows and other programs can call upon. "Kernel32" is one of those libraries and SetCurrentDirectory is one of the functions within Kernel32. Calling upon Windows DLLs allows you to do things that are not otherwise available with VBA, but there is little if any error checking on these function. Pass an incorrect value to one of these functions and you'll likely crash out Excel. Use with caution. The "Declare" statement tells the VBA compiler in which DLL a function resides and what the parameters to that function and their data types are. Cordially, Chip Pearson Microsoft Most Valuable Professional Excel Product Group, 1998 - 2009 Pearson Software Consulting, LLC www.cpearson.com (email on web site) On Wed, 27 May 2009 01:48:00 -0700, Frank Situmorang wrote: Hello, Can anyone explain, what is the meaning/purpose of this sub: Private Declare Function SetCurrentDirectoryA Lib _ "kernel32" (ByVal lpPathName As String) As Long Sub ChDirNet(szPath As String) SetCurrentDirectoryA szPath End Sub Waht is " Kernel32" Thanks for any idea Frank |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
meaning of E in y=3E-.05x^3 | Charts and Charting in Excel | |||
what is the meaning of <? | Excel Worksheet Functions | |||
Meaning of some VBA | Excel Programming | |||
Vba code meaning | Excel Programming | |||
meaning of ######### | Excel Discussion (Misc queries) |