We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Access: save Excel file to PDF... suddenly not working

mytfein
mytfein asked
on
Medium Priority
439 Views
Last Modified: 2012-05-07
Hi EE,
About 2 weeks ago, I searched thru EE as to how to save Excel file as PDF file.
Got ideas from numerous points, mainly to use ps file, distiller to create PDF file with a name.

I ran Adobe's update on pc on Friday.
The PDFtoFile of distiller is not working.... Below is a code snippet.....

I'm open to other approaches, as long as I can create pdf file, as I need to ftp the file
to a web server.

Please help... thx, sandra

Public Sub f005_CopyFromRecordSet(strSql As String, _
                                  strCPath As String, _
                                  strExcelFile As String, _
                                  strBackRevisedExcelFile As String, _
                                  strBackPDFFile As String)
 
 
Dim strExcelPath          As String
Dim strPSfile             As String
Dim strLOGfile            As String
 
 
Dim lngPos                As Long
 
Dim db                    As DAO.Database
Dim rst                   As DAO.Recordset
Dim fld                   As DAO.Field
 
 
strExcelPath = strCPath & strExcelFile
strBackRevisedExcelFile = strCPath & Mid(strExcelFile, 6)
 
Call e090_LaunchExcel
' Set objExcel = CreateObject("Excel.Application")
  
Set objExcelActiveWkbs = objExcel.Workbooks
 
Set objExcelActiveWkb = objExcelActiveWkbs.Open(Filename:=strExcelPath)
Set objExcelActiveWS = objExcel.ActiveSheet
 
objExcel.Visible = True
 
Set db = CurrentDb
Set rst = db.OpenRecordset(strSql)
 
Debug.Print strSql
 
objExcelActiveWS.Range("A2").CopyFromRecordset rst
 
 
With objExcelActiveWS
     With .Cells
          .Select
          .EntireColumn.AutoFit
          
          
          
         With Selection.Borders(xlDiagonalDown)
              .LineStyle = xlNone
         End With
         
         With Selection.Borders(xlDiagonalUp)
              .LineStyle = xlNone
         End With
          
         With Selection.Borders(xlEdgeLeft)
              .LineStyle = xlContinuous
              .Weight = xlThin
              .ColorIndex = xlAutomatic
         End With
         
         With Selection.Borders(xlEdgeTop)
             .LineStyle = xlContinuous
             .Weight = xlThin
             .ColorIndex = xlAutomatic
         End With
    
         With Selection.Borders(xlEdgeBottom)
             .LineStyle = xlContinuous
             .Weight = xlThin
             .ColorIndex = xlAutomatic
         End With
    
         With Selection.Borders(xlEdgeRight)
             .LineStyle = xlContinuous
             .Weight = xlThin
             .ColorIndex = xlAutomatic
         End With
    
         With Selection.Borders(xlInsideVertical)
             .LineStyle = xlContinuous
             .Weight = xlThin
             .ColorIndex = xlAutomatic
         End With
    
         With Selection.Borders(xlInsideHorizontal)
             .LineStyle = xlContinuous
             .Weight = xlThin
             .ColorIndex = xlAutomatic
         End With
          
     End With
     
     With .Columns("E:E")
          .Select
          Selection.NumberFormat = "mm/dd/yy;@"
     End With
 
    With .Columns("F:F")
         .Select
         Selection.NumberFormat = "mm/dd/yy;@"
    End With
    
    
    
End With
 
 
objExcel.DisplayAlerts = False
 
 
' save Excel file
objExcelActiveWkb.SaveAs Filename:= _
     strBackRevisedExcelFile, _
     FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
     ReadOnlyRecommended:=False, CreateBackup:=False
 
' Create PS, LOG, PDF file names from Excel file name
lngPos = InStr(strBackRevisedExcelFile, ".")
strPSfile = Left(strBackRevisedExcelFile, lngPos) & "ps"
strLOGfile = Left(strBackRevisedExcelFile, lngPos) & "log"
strBackPDFFile = Left(strBackRevisedExcelFile, lngPos) & "pdf"
 
Debug.Print strPSfile
Debug.Print strLOGfile
Debug.Print strBackPDFFile
 
' objExcel.ActivePrinter = "Adobe PDF"
 
' objExcel.ActivePrinter = "Adobe PDF on Ne05:"
' objExcel.ActivePrinter = "CutePDF Writer on CPW2:"
  
'save default printer
Dim strDefaultPrinter As String
strDefaultPrinter = objExcel.ActivePrinter
 
' print Excel file to Acrobat PS file
Dim objPDF_Distiller As PdfDistiller
Set objPDF_Distiller = New PdfDistiller
  
objExcel.ActiveSheet.PrintOut , Copies:=1, _
PrintToFile:=True, PrToFilename:=strPSfile
 
' Convert Acrobat PS file to PDF file
objPDF_Distiller.FileToPDF strPSfile, strBackPDFFile, ""
 
' delete work files
Kill strPSfile
Kill strLOGfile
 
Set objPDF_Distiller = Nothing
                                  
'Restore the default settings
objExcel.ActivePrinter = strDefaultPrinter
 
objExcel.DisplayAlerts = True
 
Call e110_CloseExcel(True)
 
Set objExcel = Nothing
Set objExcelActiveWkb = Nothing
Set objExcelActiveWkbs = Nothing
Set objExcelActiveWS = Nothing
 
rst.Close
db.Close
 
Set rst = Nothing
Set db = Nothing
Set fld = Nothing
 
End Sub

Open in new window

Comment
Watch Question

CERTIFIED EXPERT
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Author

Commented:
Thx TheNelson,
a) You wrote alot of info... thank you...

b) Do you have code to "print" to these printers, yet save as pdf?

pls advise, tx, sandra
   

Author

Commented:
Hi TheNelson,

I just noticed this post by you, suggesting Fox it -
   would that print a pdf to a file?

tx, sandra
CERTIFIED EXPERT
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Author

Commented:
thx  the Nelson,

ok, i'm not advanced like you...

i want to create a pdf from Excel (though I'm in Access controlling Excel)
i think the above is to create pdf from access report, which is not what i need.

(can you pls check another post that i just added to EE, I read another of your posts about printing
pdf to printer using foxit/shell, and after installing foxit for some reason i changed my my mind, and
now pdfs are opening in a reduced mode, instead of full page, and i do not know how to set
the default back....)

also, is there any way to make the acrobat distiller technique work again?
tx, s

CERTIFIED EXPERT

Commented:
<i want to create a pdf from Excel>
What I think I would do is link to the spreadsheet (In Access database window, tables, select New, then link table) and create a report that I would use to create the pdf file.

<now pdfs are opening in a reduced mode, instead of full page, >
Sorry abut that. Look like captainreiss gave you a possibl solution in question # 24530334.

<also, is there any way to make the acrobat distiller technique work again?>
I'm not all that familiar with acrobat distiller.  Why don't you add the acrobat zone to this question?

Author

Commented:
thx the nelson,
i still wantt to try from excel to pdf, before access report to pdf....
will be in touch, tx, s

Author

Commented:
Hi theNelson,

i will be closing this post - and since you provide info that would be useful for future ....

i posted a similar quest, and incidentally someone else asked a quest on this subject in the past week,
if you take a look, you will see my hoped for approach...

other wise i might try installing fox it, again, it's just that alot of my settings got switched an not sure
if fox it did that... tx, s
CERTIFIED EXPERT

Commented:
You're welcome.  Glad to help and thank you very much for the points with "A" grade!

Happy Computing!

Nelson
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.