M
Mudd
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.
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.