【问题标题】:Excel Macro Addin - location for addinExcel 宏插件 - 插件的位置
【发布时间】:2012-03-08 22:20:25
【问题描述】:

只是想知道把这个宏放在哪里。每当用户点击保存时,它应该会导致正确标记的 Excel 文件保存为 PDF。我有一个类似的宏在 Word 上没有问题,但对于我的生活,我似乎无法弄清楚这个宏的去向。

我正在使用 Excel 2007 在 Xp Sp3 上运行。我尝试将其保存在 .xlam 中的一个模块中到 C:\Program Files\Microsoft Office\Office12\XLSTARTC:\Documents and Settings\username\Local Settings\Application Data\Microsoft\Office\12.0C:\Documents and Settings\username\Templates 等,但没有乐趣?

我是否遗漏了一些明显的东西(不足为奇)?

Sub FileSave()
'
' FileSave Macro
'
'
  Dim StrFile As String
  Dim StrPath As String
  Dim StrName As String
  Dim StrPDFName As String

  StrPath = ActiveSheet.Path 'Get document path
  StrFile = ActiveSheet.Name 'Get document name

  If StrName <> "" Then

    MsgBox "We have a string name"

    StrName = Left(StrFile, (InStr(StrFile, ".") - 1))

      StrPDFName = StrPath + "\" + StrName + ".pdf"

      If InStr(StrFile, "_fmpro_temp") Then

        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= StrPDFName, _
            Quality:= xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False

        MsgBox StrName + " has been saved. " & vbNewLine & _
            "If you're finished, please close the file," & vbNewLine & _
            "and return to FileMaker to accept or discard this version.", _
            vbInformation, "FileMaker Pro Versioning"

      End If

  End If


End Sub

【问题讨论】:

  • 为什么要在第一个 If 之前添加 debug.print strPath, strFile ?我猜这应该会给你一个提示。
  • 我也试过 C:\Program Files\Microsoft Office\Office12\Startup 这应该是一个受信任的位置...
  • @Dycey:你的问题解决了吗?

标签: excel pdf-generation excel-2007 vba


【解决方案1】:

插件的位置应该不同于插件尝试保存用户文档的位置。 (即通常您不会混合程序和文档)。 您通常希望将 Excel 插件存储在两个位置之一;适用于个人电脑的所有用户或个人用户。不同之处在于,个人用户的插件通常是自定义的或临时的。 有关存储插件的位置,请参阅stackoverflow: where to store excel addin

为了存储用户的 PDF 文档,您应该为用户提供覆盖保存位置的选项,方法是使用以用户文档目录为根目录的标准打开文件对话框。

【讨论】:

  • 错误,第一点,很好。错误,第二点 - 实际上没有。插件的原因是,它是让 Excel 生成可以由另一个系统以编程方式读取的 pdf 的最简单方法 - 前提是另一个系统知道在哪里查看 ;-) 所以,覆盖保存位置是一个禁忌.
【解决方案2】:

如果这是一个 Excel 插件,那么如果你调用

Application.UserLibraryPath()

这将为您提供保存加载项的目录,类似于:C:\Documents and Settings\Username\Application Data\Microsoft\AddIns\

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-22
    • 1970-01-01
    • 2011-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-30
    相关资源
    最近更新 更多