I am working with a Word Macro. In the macro there are calls to
GetTempPathA API function. A client has XP and Word 2000 and the return
value of this call is 0 with no dll error number. So far this is the only
client that has this problem. Here is the code for the call:
Private Declare Function GetTempDir Lib "kernel32" Alias "GetTempPathA"
(ByVal nBufferLength As Long, _
ByVal lpBuffer As String) As Long

Const MAX_PATH = 260
Dim lReturnVal As Long
Dim sTempDir As String * MAX_PATH
Dim lLastDllError As Long
Dim errDesc As String

On Error GoTo Handle_Error

lReturnVal = GetTempDir(MAX_PATH, sTempDir)
If lReturnVal = 0 Then 'error
lLastDllError = Err.LastDllError

I work with another program that is written in Visual Basic and makes the
same call to get the temporary directory and writes a file in the directory.
The Word macro now needs to read this file, so I know the API calls are
working for VB but not for VBA.

Does anybody have an idea of what might be the problem?

Re: Word Macro doesn't seem to be executing any API function calls by Jay

Jay
Tue Mar 07 19:14:26 CST 2006

The best I can do is tell you that this problem has been seen before,
but no resolution was found. Google Groups turned up these two
threads:

http://groups.google.com/group/microsoft.public.excel.programming/browse_frm/thread/da0a0dd7e3fea09b/fd26c8fcb2625d88?lnk=st&q=gettemppatha+group%3Amicrosoft.public.*&rnum=1&hl=en#fd26c8fcb2625d88
http://groups.google.com/group/microsoft.public.office.misc/browse_frm/thread/38ba9935c212fb9f/e0a40db573fe499c?lnk=st&q=gettemppatha+group%3Amicrosoft.public.*&rnum=2&hl=en#e0a40db573fe499c

If you can use the Environ("Temp") function instead, that may work
where the API call doesn't.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

On Tue, 7 Mar 2006 12:55:27 -0800, bluejackethive72
<bluejackethive72@discussions.microsoft.com> wrote:

>I am working with a Word Macro. In the macro there are calls to
>GetTempPathA API function. A client has XP and Word 2000 and the return
>value of this call is 0 with no dll error number. So far this is the only
>client that has this problem. Here is the code for the call:
>Private Declare Function GetTempDir Lib "kernel32" Alias "GetTempPathA"
>(ByVal nBufferLength As Long, _
> ByVal lpBuffer As String) As Long
>
>Const MAX_PATH = 260
> Dim lReturnVal As Long
> Dim sTempDir As String * MAX_PATH
> Dim lLastDllError As Long
> Dim errDesc As String
>
> On Error GoTo Handle_Error
>
> lReturnVal = GetTempDir(MAX_PATH, sTempDir)
> If lReturnVal = 0 Then 'error
> lLastDllError = Err.LastDllError
>
>I work with another program that is written in Visual Basic and makes the
>same call to get the temporary directory and writes a file in the directory.
>The Word macro now needs to read this file, so I know the API calls are
>working for VB but not for VBA.
>
>Does anybody have an idea of what might be the problem?