Create Button for form

MariPip

New Member
Joined
Jul 16, 2014
Messages
29
Hi there!
I'm trying to create a button that saves the information thas is in predifined cells of a Worksheet onto a PDF document on a specific location and resets the value of the cells!
I hope I was clear enough explaining it...
Thank you!
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Try using this code. You can assign the macro to a form control button if you wish.

Code:
Sub Test()

    Dim ExportRange As Range
    Dim FName As String
    
    'Set range to be exported
    Set ExportRange = Worksheets("Sheet1").Range("A1:J10")
    
    'Set filename for export
    FName = "C:\Users\jsmith\Desktop\Book1.pdf"
    
    'Export the range
    ExportRange.ExportAsFixedFormat _
        Type:=xlTypePDF, _
        Filename:=FName
    
    'Clear contents of exported range
    ExportRange.ClearContents
    
End Sub
 
Upvote 0
Thank you so much!!
Try using this code. You can assign the macro to a form control button if you wish.

Code:
Sub Test()

    Dim ExportRange As Range
    Dim FName As String
    
    'Set range to be exported
    Set ExportRange = Worksheets("Sheet1").Range("A1:J10")
    
    'Set filename for export
    FName = "C:\Users\jsmith\Desktop\Book1.pdf"
    
    'Export the range
    ExportRange.ExportAsFixedFormat _
        Type:=xlTypePDF, _
        Filename:=FName
    
    'Clear contents of exported range
    ExportRange.ClearContents
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,303
Messages
6,129,984
Members
449,550
Latest member
LML2892

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top