2016-08-02 81 views
-1

的意外標識符我已經刪除了以下全局變量。這些將被模塊使用。VBa編譯錯誤:私人類型**** EMID

但是在「私有類型**** EMID」行我得到一個編譯錯誤:預期的標識符。 我從來沒有使用過這些聲明。你能建議需要做什麼嗎?

'- to get Explorer folder 
Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" _ 
    (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ITEMIDLIST) As Long 
Const CSIDL_WINDOWS = &H24 
'--------------------------------------------------------------------------------------------------------- 
Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" _ 
    (ByVal pidl As Long, ByVal pszPath As String) As Long 
'--------------------------- 
Private Type ****EMID 
    cb As Long 
    abID As Byte 
End Type 
'--------------------------- 
Private Type ITEMIDLIST 
    mkid As ****EMID 
End Type 
'--------------------------------------------------------------------------------------------------------- 

回答

0

您需要刪除星號。

EMID和ITEMIDLIST是自定義數據類型不是全局變量。

這裏是你的代碼是這樣做的:

變量PIDL作爲類型ITEMIDLIST被傳遞的ByRef作爲參數傳遞給它在動態鏈接庫(DLL)中發現的Win32函數SHGetSpecialFolderLocation:shell32.dll中。該函數將從pidl變量中檢索和/或設置值。在這種情況下,它正在設置它的值。

'- to get Explorer folder 
Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" _ 
    (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ITEMIDLIST) As Long 
Const CSIDL_WINDOWS = &H24 
'--------------------------------------------------------------------------------------------------------- 
Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" _ 
    (ByVal pidl As Long, ByVal pszPath As String) As Long 
'--------------------------- 
Private Type EMID 
    cb As Long 
    abID As Byte 
End Type 
'--------------------------- 
Private Type ITEMIDLIST 
    mkid As EMID 
End Type 
'--------------- 

我會用一個FileSystemObject的GetTempName Method代替API調用的。

Function getTempFileName() As String 
    Const TemporaryFolder = 2 
    Dim fso 
    Set fso = CreateObject("Scripting.FileSystemObject") 

    getTempFileName = fso.GetSpecialFolder(TemporaryFolder).Path & "\" & fso.GetTempName 

    Set fso = Nothing 
End Function 
+0

謝謝Thomas。我脫掉了****,它的工作! – Nash

+0

歡迎您。感謝您的複選標記! – 2016-08-04 15:49:07