简体   繁体   中英

Excel Macro Addin - location for addin

just wondering where to put this macro. It's supposed to cause correctly labelled excel files ato save as PDF as well whenever the user hits save. I have a similar Macro working without issue for Word, but for the life of me I can't seem to work out where this macro goes.

I'm running on Xp Sp3 with Excel 2007. I've tried saving it in a module within a .xlam to 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 etc. but no joy?

Am I missing something obvious (no surprise)?

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 this is to be an Excel Add-in, then if you call

Application.UserLibraryPath()

That will give you the directory to save add-ins to which will be something like: C:\\Documents and Settings\\Username\\Application Data\\Microsoft\\AddIns\\

The location of the addin should be different from where the addin tries to save the user's documents. (ie in general you don't mix programs and documents). You typically want to store an Excel addin in one of two places; either for all users of the pc or for an individual user. The difference is, addins for individual users are typically custom or adhoc. For the locations to store the addins, see stackoverflow: where to store excel addin

For storing the user's PDF document, you should give the user the option of overriding the save location by using the standard open file dialog that has been primed with the user's document directory as the root.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM