LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default VBA macro to obtain file names using WIN32 API

I have a problem trying to get an Excel VBA macro to use a Win32 API
function.
In the macro, I defined the variable structBuffer in the Declarations
section as;
Type WIN32_FIND_FILE_DATA
FileAttributes As Long
CreationTime As String
AccessTime As String
WriteTime As String
SizeHigh As Long
SizeLow As Long
Reserved0 As Long
Reserved1 As Long
FileName As String
FileAltName As String * 14
End Type
to match the Win32 struct which is defined as;
typedef struct _WIN32_FIND_DATA { // wfd
DWORD dwFileAttributes;
FILETIME ftCreationTime;
FILETIME ftLastAccessTime;
FILETIME ftLastWriteTime;
DWORD nFileSizeHigh;
DWORD nFileSizeLow;
DWORD dwReserved0;
DWORD dwReserved1;
TCHAR cFileName[ MAX_PATH ];
TCHAR cAlternateFileName[ 14 ];
} WIN32_FIND_DATA;

and I defined the Win32 API function FindFirstFile() like this;
Declare Function FindFirstFile Lib "kernel32" _
Alias "FindFirstFileA" (ByVal lpFileName As String, _
lpFindFileData As WIN32_FIND_FILE_DATA) _
As Long

I define the structBuffer variable like this;
Dim stuctBuffer As WIN32_FIND_FILE_DATA

I have these two lines in the macro.
strFullPath = strPath & "\*.*"
lnHandle = FindFirstFile(strFullPath, structBuffer)

strPath is the drive and directory path to the Temporary Internet Files
directory (that holds cookies, shortcuts, etc).

When I try to run the macro, it flags this line
lnHandle = FindFirstFile(strFullPath, structBuffer)
as a Compile error: ByRef argument type mismtach as it highlights
structBuffer.
I don't understand what I have done wrong. I'm sure I'm on the right track
here so hopefully it's something quite simple.
I have been using the VBA Dir() function to obtain file names in other
directories but the Temporary Internet Files directory returns nothing to
the Dir() function. A DIR command at the command prompt in this directory
also shows nothing, but Windows Explorer is quite capable of listing all the
cookies, URLs etc that fill up this directory.
This is why I am trying to use the Win32 API instead of the VBA functions.


 
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
Macro recorded... tabs & file names changed, macro hangs Steve Excel Worksheet Functions 3 October 30th 09 11:41 AM
Macro File Names John Excel Worksheet Functions 2 December 5th 08 06:27 AM
Macro File Names John Excel Worksheet Functions 1 December 5th 08 06:23 AM
Cant open Execl file-Not a valid win32 Application Albert Excel Discussion (Misc queries) 0 August 10th 08 08:34 AM
Not a valid Win32 file ? davestanyon Setting up and Configuration of Excel 0 May 9th 05 05:54 PM


All times are GMT +1. The time now is 09:04 PM.

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

About Us

"It's about Microsoft Excel"