Convert active excel wksht to pdf file [Solved/Closed]

Report
-
 onedog1 -
Hello,
I'm trying to figure out how to create a macro to save an range selected in an active worksheet and save to a pdf file by clicking an inserted button.
Posts
4475
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
January 6, 2016
755
If you record your action, it will give you a macro template. Then you can modify it to suit your needs
I'm not very saavy in macros, so i've been able to get to the point yoiu suggested, I want to enhance now by prompting the user to save to file by clicking an inserted button.
rizvisa1
Posts
4475
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
January 6, 2016
755 > onedog
Could you explain what you mean prompt the user to save. Under what conditions the used is asked to save the file and why ask the user, if it can be saved on its own via macro or when user try to close the file excel will prompt. A little more background might help
> rizvisa1
Posts
4475
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
January 6, 2016

Below is the vb script for where I'm at right now. All this does right now is open up the pdf file of the range wanted saved. before opening, I want to prompt the user to enter a filename. Thanks.

Sub SaveSO()
'
' SaveSO Macro
'

'
Range("B2:I50").Select
Range("I2").Activate
ChDir "C:\"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Desktop\book1.pdf", Quality _
:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=True
End Sub
Posts
4475
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
January 6, 2016
755
I guess you are saying that you want user to enter a name for pdf file that you would use then in the code.

    Dim fileName As String
    
    fileName = ""
    Do While (fileName = "")
    
        fileName = InputBox("Save file as..", "Enter File name", "book1")
        
        fileName = Trim(fileName)
    Loop
    
    ActiveSheet.ExportAsFixedFormat _
            Type:=xlTypePDF, _
            fileName:="C:\Desktop\" & fileName & ".pdf", _
            Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, _
            IgnorePrintAreas:=False, _
            OpenAfterPublish:=True


> rizvisa1
Posts
4475
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
January 6, 2016

I just uploaded my file.
rizvisa1
Posts
4475
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
January 6, 2016
755 > onedog
You forgot to post the link here
> rizvisa1
Posts
4475
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
January 6, 2016

The site showed me it was uploaded. see the following link
http://www.speedyshare.com/files/21396235/Copy_of_Longo_Dryer_Quote.xls
rizvisa1
Posts
4475
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
January 6, 2016
755 > onedog
You have code incorrect

See my message above
http://ccm.net/forum/affich-283846-convert-active-excel-wksht-to-pdf-file?#9


1. Remove all lines starting from

Sub SaveSO()

till the last line [ OpenAfterPublish:=True ( that you pasted from my earlier message) ]

2. Paste the code that is in

http://ccm.net/forum/affich-283846-convert-active-excel-wksht-to-pdf-file?#9

3. Make sure you have a sub folder or directory c:\desktop. If you do not have it, create one
> rizvisa1
Posts
4475
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
January 6, 2016

Thank you. Thank you.