+ Reply to Thread
Results 1 to 8 of 8

Excel VBA 2003 2010 Compatibility with ExportAsFixedFormat

Hybrid View

  1. #1
    Registered User
    Join Date
    10-25-2012
    Location
    Washington DC
    MS-Off Ver
    For MS 365
    Posts
    54

    Excel VBA 2003 2010 Compatibility with ExportAsFixedFormat

    The code below runs great in Excel 2010, but hangs with a "Object doesn't support this property or method" error on the line with the ExportAsFixedFormat statement near the bottom. Is this a syntax issue or does ExportAsFixedFormat really not exist in Office 2003 objects?

    I searched for this for a while, but then remembered that the people here generally explain things much better than the MS reference sites.

    Sorry for the long sub but posting the whole thing seems to be best.

    Thanks.

    Sub cCreateContractAwardDocuments() 'Creates a PDF from the contract award document template
        Dim wd As Word.Application
        Dim wdocSource As Word.Document
        Dim i As Long, j As Long
        Dim ContractRecord As Long
        Dim PDFPath As String
        Dim PDFFileName As String
    
        On Error Resume Next
        Set wd = GetObject(, "Word.Application")
        If wd Is Nothing Then
            Set wd = CreateObject("Word.Application")
        End If
        On Error GoTo 0
        ContractRecord = ActiveCell.Row
        MasterWordFile = Workbooks(TableFileName).Sheets("Administrative").Range("$B$8").Value & _
            Workbooks(TableFileName).Sheets("Administrative").Range("$B$11").Value & "\" & _
            Workbooks(TableFileName).Sheets("Administrative").Range("$B$13").Value
        PDFPath = Workbooks(TableFileName).Sheets("Administrative").Range("$B$8").Value & _
            Workbooks(TableFileName).Sheets("Administrative").Range("$B$9").Value & "\" & _
            AwardFolderID(ContractRecord) & "\" & _
            "3 Award\"
        PDFFileName = PDFPath & Workbooks(TableFileName).Sheets("Administrative").Range("$B$12").Value
        If Not FolderExists(PDFPath) Then
            MsgBox "An award folder for the row you have selected does not exist. You must first select a cell on the applicable ROW and run the CreateNewAwardFolder."
            Exit Sub
            Else
        End If
        If FolderExists(PDFFileName) Then
            Response = MsgBox("A PDF named:" & vbCrLf & vbCrLf & PDFFileName & vbCrLf & vbCrLf & "already exists. Overwrite?", vbYesNo)
            If Response = vbNo Then
                Exit Sub
            Else
            End If
        Else
        End If
        Set wdocSource = wd.Documents.Add(MasterWordFile)
        With ActiveSheet.Range("A1")
            For i = 1 To .CurrentRegion.Columns.Count
                wdocSource.Variables.Item(.Offset(0, i - 1)).Value = ScrubData(.Offset(ActiveCell.Row - 1, i - 1))
            Next i
                If wdocSource.Variables.Item("AE Firm Contract Number").Value = " " Then
                    wdocSource.Variables.Item("AE Firm").Value = "AE Firm Not Applicable"
                End If
        End With
        With wdocSource
            .Range.Fields.Update
            .ExportAsFixedFormat PDFFileName, 17
            .Close SaveChanges:=False
        End With
        wd.Quit
        Set wdocSource = Nothing
        Set wd = Nothing
        
        If FolderExists(PDFFileName) = True Then
            MsgBox "Contract award documents successfully created and stored in:" & vbCrLf & vbCrLf & PDFFileName
        Else
            MsgBox "There was a problem." & vbCrLf & vbCrLf & "The contract documents were not created."
            Exit Sub
        End If
    End Sub

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Excel VBA 2003 2010 Compatibility with ExportAsFixedFormat

    It really doesn't exist in 2003, it was added in 2007.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    10-25-2012
    Location
    Washington DC
    MS-Off Ver
    For MS 365
    Posts
    54

    Re: Excel VBA 2003 2010 Compatibility with ExportAsFixedFormat

    Thank you. Does 2003 have a similar method of outputting a PDF?

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Excel VBA 2003 2010 Compatibility with ExportAsFixedFormat

    Not that I know of.

    I think you might need to use some sort of PDF creator add-in, or if you have the right drivers you can print to PDF.

  5. #5
    Registered User
    Join Date
    10-25-2012
    Location
    Washington DC
    MS-Off Ver
    For MS 365
    Posts
    54

    Re: Excel VBA 2003 2010 Compatibility with ExportAsFixedFormat

    Thanks Norie.

    When I put this code in I get a "Named argument not found" error, and Filename is highlighted. This code came from a Word 2003 macro recording so I don't understand the error. PDFFileName is defined as a string, but even if I change it to a variant I get the same error.

    Any idea why?


                .PrintOut Filename:=PDFFileName, Range:=wdPrintAllDocument, Item:= _
                    wdPrintDocumentWithMarkup, Copies:=1, Pages:="", PageType:= _
                    wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=True, _
                    PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
                    PrintZoomPaperHeight:=0

  6. #6
    Registered User
    Join Date
    10-25-2012
    Location
    Washington DC
    MS-Off Ver
    For MS 365
    Posts
    54

    Re: Excel VBA 2003 2010 Compatibility with ExportAsFixedFormat

    My apologies. This is the code I am using in 2003. The code above is from 2010.

                .PrintOut Filename:=PDFFileName, Range:=wdPrintAllDocument, Item:= _
                    wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
                    ManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile:=True, _
                    PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
                    PrintZoomPaperHeight:=0

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644
    If that code is from Word you can't use it in Excel.

  8. #8
    Registered User
    Join Date
    10-25-2012
    Location
    Washington DC
    MS-Off Ver
    For MS 365
    Posts
    54

    Re: Excel VBA 2003 2010 Compatibility with ExportAsFixedFormat

    Understood. I thought I should get it from Word since I am using in a "With" statement referring to a Word object, and I guess I thoguht the object methods were the same throughout an Office suite. Rookie mistake no doubt. Will try it through Excel. Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1