Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
meaning of E in y=3E-.05x^3 Garland Charts and Charting in Excel 2 April 4th 23 12:44 PM
what is the meaning of <? bitwhite Excel Worksheet Functions 3 July 13th 09 04:02 PM
Meaning of some VBA Frank Situmorang[_2_] Excel Programming 4 April 1st 08 10:05 AM
Vba code meaning andresg1975 Excel Programming 2 November 17th 06 05:21 PM
meaning of ######### dick Excel Discussion (Misc queries) 2 January 10th 06 01:28 PM


All times are GMT +1. The time now is 08:20 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"