Convert active excel wksht to pdf file

Solved/Closed
onedog - Mar 11, 2010 at 06:03 PM
 onedog1 - Mar 15, 2010 at 09:15 AM
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.
Related:

2 responses

rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Mar 12, 2010 at 04:38 AM
If you record your action, it will give you a macro template. Then you can modify it to suit your needs
0
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.
0
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766 > onedog
Mar 12, 2010 at 08:57 AM
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
0
onedog > rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022
Mar 12, 2010 at 09:52 AM
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
0
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Mar 12, 2010 at 10:14 AM
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


0
Thank you. I'll try this...
0
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766 > onedog
Mar 12, 2010 at 01:47 PM
Good luck. Post your result back so that it may help some one else down the road.
0
Your suggestion isn't working as I get a debug error and when I go back into vb the following is highlighted in yellow:
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
fileName:="C:\Desktop\" & fileName & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True

The following is the entire routine in the macro:
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


End Sub
0
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766 > onedog
Mar 12, 2010 at 02:28 PM
Could you possibly put the file at https://authentification.site or some other share site

Two things.
1. Do you have a folder C:\desktop, as that's where the file is being saved. Else you have to change that to point to right location

2. The full macro would have been

Sub SaveSO()
    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


End Sub
0
onedog > rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022
Mar 12, 2010 at 02:49 PM
I just uploaded my file.
0