【发布时间】:2012-03-08 22:20:25
【问题描述】:
只是想知道把这个宏放在哪里。每当用户点击保存时,它应该会导致正确标记的 Excel 文件保存为 PDF。我有一个类似的宏在 Word 上没有问题,但对于我的生活,我似乎无法弄清楚这个宏的去向。
我正在使用 Excel 2007 在 Xp Sp3 上运行。我尝试将其保存在 .xlam 中的一个模块中到 C:\Program Files\Microsoft Office\Office12\XLSTART、C:\Documents and Settings\username\Local Settings\Application Data\Microsoft\Office\12.0、C:\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