![]() |
What is the meaning of this sub
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 |
What is the meaning of this sub
Frank
Kernel32.dll is a dynamic link library found in the windows operating system kernel which handles memory management, IO operrations etc; The below function will set the current directory as what is specified. For example the below code will change the directory to \\fnp01\common ChDirNet "\\fnp01\common" If this post helps click Yes --------------- Jacob Skaria "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 |
What is the meaning of this sub
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 |
All times are GMT +1. The time now is 11:12 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com