【问题标题】:Getting Compile Error: User-defined type not defined when working to make an old 32-bit template into a Word 2012 64-bit template出现编译错误:将旧的 32 位模板转换为 Word 2012 64 位模板时未定义用户定义的类型
【发布时间】:2015-04-09 14:20:51
【问题描述】:

我有一个照片模板,它可以从文件中抓取照片并将它们放在 word 文档中的各个框中。该文件曾经是 Word 2003 32 位文件,只能在我们的旧计算机上运行。

我已将文件转换为 64 位以在我们的新计算机中使用,并将其保存为支持 word 宏的模板。 这消除了我遇到的一堆问题,但最后一点是......起初它显示检测到模糊的名称,但在它关闭并重新启动后它开始显示编译错误:用户定义type not defined 突出显示下面代码的第一行,经过大量研究后我找不到解决方案。 请帮忙,我真的需要这个宏来工作

Public Declare PtrSafe Function SHBrowseForFolder Lib "shell32.dll" (ByRef lpbi As BROWSEINFO) As Long*

Public Declare PtrSafe Function SHGetPathFromIDList Lib "shell32.dll" (ByVal pidList As Long, ByVal lpBuffer As String) As Long

'corrected
Public Declare PtrSafe Function SHGetSpecialFolderLocation Lib "shell32.dll" _
(ByVal hwndOwner As Long, ByVal nFolder As Long, ByRef pidl As Long) As Long



Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadId As Long
End Type


Private Declare PtrSafe Function WaitForSingleObject Lib "kernel32" (ByVal _
hHandle As Long, ByVal dwMilliseconds As Long) As Long

Private Declare PtrSafe Function CreateProcessA Lib "kernel32" (ByVal _
lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
lpStartupInfo As STARTUPINFO, lpProcessInformation As _
PROCESS_INFORMATION) As Long

Private Declare PtrSafe Function CloseHandle Lib "kernel32" (ByVal _
hObject As Long) As Long


Private Type FILETIME ' 8 Bytes
dwLowDateTime As Long
dwHighDateTime As Long
End Type

【问题讨论】:

    标签: vba templates compiler-errors 32bit-64bit ms-word


    【解决方案1】:

    您似乎缺少 BROWSEINFOType 枚举,例如,请参见此处:

    http://www.jkp-ads.com/Articles/apideclarations.asp

    #If VBA7 Then
        Private Type BROWSEINFO
            hOwner As LongPtr
            pidlRoot As LongPtr
            pszDisplayName As String
            lpszTitle As String
            ulFlags As Long
            lpfn As LongPtr
            lParam As LongPtr
            iImage As Long
        End Type
    
        Private Declare PtrSafe Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" _
            (lpBrowseInfo As BROWSEINFO) As LongPtr
    #Else
        Private Type BROWSEINFO
            hOwner As Long
            pidlRoot As Long
            pszDisplayName As String
            lpszTitle As String
            ulFlags As Long
            lpfn As Long
            lParam As Long
            iImage As Long
        End Type
    
        Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" _
            (lpBrowseInfo As BROWSEINFO) As Long
    #End If
    Private Const BIF_RETURNONLYFSDIRS = &H1
    

    【讨论】:

    • 谢谢!这似乎有帮助......现在似乎有很多额外的问题将它转换为我需要的东西......我对此很陌生,所以我只是想弄清楚......它现在告诉我调用 BrowseForFolder(dhcCSIdlDesktop, dhcBifReturnOnlyFileSystemDirs, _ strPath, pszTitle:="Select an image folder: Criterium Photo Project") 编译错误:未为 dhcCSIdlDesktop 部分定义变量。这一切之前都运行良好。
    • 我不是真的来牵着你的手完成调试过程...要么这回答了最初的问题,要么它没有...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-22
    • 2018-12-26
    相关资源
    最近更新 更多