Hello,
I am trying to convert my excel into pdf file. my excel file is saved on a shared folder (Server), i tried to save it in shared folder itself, it refused. I tried also to save it on the desktop is refused also. I have create a user form. when i select a specific or multi sheets it should convert to pdf.
I appreciate your help.
Thank you.
I am trying to convert my excel into pdf file. my excel file is saved on a shared folder (Server), i tried to save it in shared folder itself, it refused. I tried also to save it on the desktop is refused also. I have create a user form. when i select a specific or multi sheets it should convert to pdf.
VBA Code:
Private Sub CommandButton1_Click()
Dim user As String: user = Environ("username") 'Sets the system user ID
Dim fPath As String: fPath = "C:\Users\" & user & "\Desktop\" 'Can change Desktop to any other folder
'Dim fName As String: fName = "Test"
Dim sheet_names As String
Dim sh As Worksheet
Set sh = ActiveSheet
Dim i, x As Long
x = 0
sheet_names = ""
For i = 0 To Me.ListBox1.ListCount - 1
If Me.ListBox1.Selected(i) Then
If x = 0 Then
sheet_names = Me.ListBox1.List(i)
Else
sheet_names = sheet_names & "*" & Me.ListBox1.List(i)
End If
x = x + 1
End If
Next i
If x = 0 Then
MsgBox "Please select the sheet form sheet list", vbCritical
Exit Sub
End If
'''''' I tried this one first and it return error
ActiveWorkbook.Sheets(Split(sheet_names, "*")).Select
'ActiveSheet.ExportAsFixedFormat xlTypePDF,VBA.Environ ("Temp") & Application.PathSeparator & Format(Now, "DDMMYYHHMMSS") & ".pdf", , , , , , True
'''''''''''also i tried this code and it returns error
ActiveSheet.ExportAsFixedFormat xlTypePDF, Filename:= _
"\\hmcfs10\HGH Shared Governance\Reports\Test.pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
sh.Select
End Sub
I appreciate your help.
Thank you.