hi,
I want to create a pdf from excel sheet using visual basic 6.0. Can you people help me describing or sending me a ready codes regarding the same.
Thanks with regards,
Sayyad H.A.
India.

hi,

try the below coding.

Public Function ConvertFile(strSourceFileName As String) As Boolean
    On Error GoTo ErrorHandler
    
    Dim msExcel As Excel.Application
    Set msExcel = GetObject(Class:="Excel.Application")
    
    Dim p As String
    p = "Acrobat Distiller on Ne00:"
    
    msExcel.Visible = False
    msExcel.Workbooks.Open strSourceFileName
    strMenuFilePs = strSourceFileName
    msExcel.ActiveWorkbook.PrintOut ActivePrinter:=p, PrintToFile:=False, PrToFileName:=strMenuFilePs
    strMenuFilePDF = "c:\try.pdf"
    Dim myPDF As PdfDistiller
    Set myPDF = New PdfDistiller
    myPDF.FileToPDF strMenuFilePs, strMenuFilePDF, ""
    Set myPDF = Nothing
    msExcel.ActiveWorkbook.Close False
    
    ' Should check and quit excel when done
   msExcel.Quit
    Set msExcel = Nothing
    ConvertFile = True
Exit Function

ErrorHandler:
    ' Create Excel for the first time if it is not active
    If Err.Number = 429 Then
        Set msExcel = CreateObject("Excel.Application")
        Err.Clear ' Clear Err object in case error occurred.
        Resume
    End If

    ' All other errors handled here
    If IsCriticalError Then
        ConvertFile = False
        Exit Function
    Else
        Resume
    End If
End Function

best regards
shailu

I have a VB script which saves worksheets as its own workbook. How could I get it to save it as a pdf? I'm using Adobe Acrobat Professional and its Reference Libraries.

Please help!

Sub Separate() 
Dim s as String, sh as worksheet 
For Each sh In ThisWorkbook.Worksheets
If sh.Visible Then 'ignores hidden sheets
sh.Copy 
s = "c:\Separated Sheets\" & sh.Name  'location and names of workbooks 
ActiveWorkbook.SaveAs Filename:=s 
Range("A1:IV5000").Copy  'selects all cells 
Range("A1").PasteSpecial Paste:=xlPasteValues  'pastes values only 
Application.CutCopyMode = False 
Range("A1").Select 'this is just to take the cursor 
'back to the top to make that sheet a litte "cleaner" 
ActiveWorkbook.Close SaveChanges:=True 
End If
Next sh 
End Sub

Im trying to automaically save an excel file to pdf file using visual basic. So, I will manually open the excel, upon opening the excel file, it will run code to calculate a daily totalizer(this I have functioning) as soon as this code finishes, I want the excel file to print/save to pdf and close. I apologize, I'm a bit of a beginner. thanks

pBunkers, welcome first of all to Daniweb.:)

We do unfortunately do not allow the hijacking of other peoples posts, especially when they are as old as this (2008).;)

Please post your own thread and I promise we will help.

Have a look at THIS post discussing the same scenario...

AndreRet

Thanks for the advice and direction. I started a new thread for my question. I'm not sure how a person finds my new thread, short searching for it. I currently reviewing the post you forward the link on to me. thanks pbunkers

Its a pleasure. I'll have a look at your new post. It will be found under vb6 forum "Software Development/VB4/5/6".:)

AndreRet

Thanks for helping and yes, it is located under "Software Development/VB4/5/6". thanks pbunkers

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.