Save as PDF and keep file name from multiple cell

Lagrande

New Member
Joined
Aug 20, 2020
Messages
7
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hi!
I am a true newbie with VBA.
I found this code to work with a button click and i need help to add a way to choose where i want to save my pdf files with the filename generate by this code. For the moment its saving on the Desktop without any choice but i prefer to choose the right folder.

Thanks
-------------------------------------
Private Sub cbSaveAsPDF_Click()

Dim sPath As String, sFile As String, sFullName As String

On Error GoTo ErrHandler

If Not IsEmpty(Me.Range("B2")) Then

sPath = ThisWorkbook.Path & Application.PathSeparator

sFile = Me.Range("B2").Value & Format(Range("I2").Value, "hh-mm-ss") & ".pdf"

sFullName = sPath & sFile

Me.ExportAsFixedFormat _

Type:=xlTypePDF, _

FileName:=sFullName, _

Quality:=xlQualityStandard

End If

ExitHandler:

Exit Sub

ErrHandler:

MsgBox "Erreur : " & Err.Number & Chr(10) & Err.Description

Resume ExitHandler

End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Try:
VBA Code:
Private Sub cbSaveAsPDF_Click()
    Dim sPath As String, sFile As String, sFullName As String
    With Application.FileDialog(msoFileDialogFolderPicker)
        .AllowMultiSelect = False
        .Show
        If .SelectedItems.Count > 0 Then
            sPath = .SelectedItems(1)
            Cancel = True
        End If
    End With
    If Not IsEmpty(Range("B2")) Then
        sFile = Range("B2").Value & Format(Range("I2").Value, "hh-mm-ss") & ".pdf"
        sFullName = sPath & "\" & sFile
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=sFullName, Quality:=xlQualityStandard
    End If
End Sub
 
Upvote 0
Great its working perfectly!
I have now another problem.....i have created a cloud (One Drive) to save these pdf. Its working for me, when i want to choose which folder i see my OneDrive folder but even if its shared and editable (full access) for other people...they don't see this folder in the pop up window. Do you have and idea?
 
Upvote 0
Unfortunately, I don't have any experience using One Drive. Sorry. :(
 
Upvote 0
I found it...people have to sync the folder in One Drive :) Thanks a lot for your help!
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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