VBA参考文件路径默认为错误的文件路径。

huangapple go评论83阅读模式
英文:

VBA reference filepath defaults to the wrong filepath

问题

我大约一个月前开始学习VBA,但现在我已经对它相当熟悉了。目前,我正在尝试将Excel数据导出为PDF,并指定特定字段,但这不是我的问题……还不是。我无法让VBA识别正确的acrobat.tlb文件。

我不知道该怎么办,根据我所做的研究,我无法找到解决方案。这个问题已经困扰我多天了。我已经重新启动了我的电脑、Excel和Adobe。我不知道该怎么办。

任何帮助都将不胜感激。

我在一台工作电脑上,上面安装了Acrobat 2020标准版和Acrobat Reader两者都有。根据我的查找,我猜想VBA试图使用Acrobat Reader而不是Acrobat标准版,因为它一直给我报“没有这样的接口”的错误。我彻底从电脑和回收站中删除了Acrobat Reader。但是,每当我选择正确的acrobat.tlb文件时,它会将文件路径更改为不正确的文件,而现在这个文件甚至都不存在了。与Acrobat Reader相关联的文件位于“Program Files”中,而与Acrobat标准版相关联的文件位于“Program Files(x86)”中。我可以在引用窗口中选择正确的文件,但只要我重新打开引用窗口,它就会更改文件路径。我已经使用宏从“引用”列表中删除了引用,但在我选择了正确文件后,重新打开引用窗口后,它仍然会恢复到错误的文件路径。

选择文件时的文件路径:C:\Program Files (x86)\Adobe\Acrobat 2020\Acrobat\acrobat.tlb
在此处输入图片描述

重新打开引用窗口后的文件路径:C:\Program Files\Adobe\Acrobat DC\Acrobat\acrobat.tlb
在此处输入图片描述

在“引用”列表的底部有一个允许我选择正确文件路径的框,但选择它不会产生任何效果。

英文:

I picked up VBA about a month ago but I've gotten pretty comfortable with it. right now I am trying to export excel data into a pdf with specific fields but that isn't my issue... yet. I cannot get VBA to recognize the correct acrobat.tlb file.

I have no idea what to do and from the research I have done I have been unable to find a solution. This is an issue I have been having for multiple days. I have restarted my computer, excel, adobe. I don't know what to do.

Any help is appreciated.

I am on a work computer which had both Acrobat 2020 Standard and Acrobat Reader installed. From what I looked up I figured that VBA was trying to use Acrobat Reader instead of Acrobat Standard because it kept giving me the "no such interface" error. I deleted Acrobat Reader completely from the computer and recycle bin. But, whenever I select the correct acrobat.tlb file it changes the filepath to the incorrect file which now doesn't even exist. The file associated with Acrobat Reader was in Program Files and the one associated with Acrobat Standard was in Program Files (x86). I can select the correct file from the references window but as soon as I reopen the references window it changes the filepath. I have used a macro to delete the reference from the References list but it will still revert back to the wrong filepath after reopening the references window after I have selected the correct file.

Filepath when choosing file: C:\Program Files (x86)\Adobe\Acrobat 2020\Acrobat\acrobat.tlb
enter image description here

Filepath after reopening reference window: C:\Program Files\Adobe\Acrobat DC\Acrobat\acrobat.tlb
enter image description here

A box allowing me to select the correct filepath remains at the bottom of the References list but selecting doesn't do anything.

答案1

得分: 0

你是否尝试使用Guid和版本号来添加引用,而不是使用文件路径?
参见:使用Guid或文件路径添加引用
你可以尝试通过浏览注册表或使用以下代码来查找Guid:Find_tlib "acrobat"

Sub Find_tlib(searchkey As String)
    Const HKEY_CLASSES_ROOT = &H80000000
    Dim Result As Long, oReg As Object, Guid As Variant, SubKeys() As Variant, Versions() As Variant, Version As Variant, Values() As Variant, Value As Variant, Types As Variant
    Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
    oReg.EnumKey HKEY_CLASSES_ROOT, "Typelib\", SubKeys
    For Each Guid In SubKeys
        Result = oReg.EnumKey(HKEY_CLASSES_ROOT, "Typelib\" & Guid & "\", Versions)
        If Result = 0 Then
           On Error Resume Next
           For Each Version In Versions
               Result = oReg.GetStringValue(HKEY_CLASSES_ROOT, "Typelib\" & Guid & "\" & Version, "", Value)
               If Result = 0 Then
                  If InStr(LCase(Value), LCase(searchkey)) > 0 Then
                     Debug.Print Guid, "Version " & Version, Value
                  End If
               End If
           Next
           On Error GoTo 0
        End If
    Next
End Sub
英文:

Did you try to add the reference using the Guid and version instead of the file path?
See also: References using Guid or FilePath
You can try to find the guid by browsing the registry or using this code: Find_tlib "acrobat"

Sub Find_tlib(searchkey As String)
    Const HKEY_CLASSES_ROOT = &H80000000
    Dim Result As Long, oReg As Object, Guid As Variant, SubKeys() As Variant, Versions() As Variant, Version As Variant, Values() As Variant, Value As Variant, Types As Variant
    Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
    oReg.EnumKey HKEY_CLASSES_ROOT, "Typelib\", SubKeys
    For Each Guid In SubKeys
        Result = oReg.EnumKey(HKEY_CLASSES_ROOT, "Typelib\" & Guid & "\", Versions)
        If Result = 0 Then
           On Error Resume Next
           For Each Version In Versions
               Result = oReg.GetStringValue(HKEY_CLASSES_ROOT, "Typelib\" & Guid & "\" & Version, "", Value)
               If Result = 0 Then
                  If InStr(LCase(Value), LCase(searchkey)) > 0 Then
                     Debug.Print Guid, "Version " & Version, Value
                  End If
               End If
           Next
           On Error GoTo 0
        End If
    Next
End Sub

答案2

得分: 0

我的问题是,我正在运行64位的Excel,而Acrobat Standard是32位的版本。我的计算机比我聪明,它试图查找acrobat.tlb的64位版本,这就是为什么它不断创建到Program Files(用于64位程序)而不是Program Files (x86)的文件路径,尽管后者并不存在。我通过重新安装32位形式的Office来解决了这个问题。

希望这对其他遇到同样问题的人有所帮助。

英文:

Ok so,

My problem was that I was running 64-bit Excel and a 32-bit version of Acrobat Standard. My computer was smarter than me and was trying to find a 64-bit version of acrobat.tlb which is why it kept creating a filepath to Program Files (which is for 64-bit programs) and not Program Files (x86) even though it didn't exist. I fixed this problem by reinstalling Office in its 32-bit form.

Hope this is helpful for anyone else struggling with the same problem.

huangapple
  • 本文由 发表于 2023年6月16日 03:12:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76484848.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定