Document not Saved!

MAlhash

New Member
Joined
Mar 26, 2023
Messages
41
Office Version
  1. 365
Platform
  1. Windows
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.

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.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,215,069
Messages
6,122,951
Members
449,095
Latest member
nmaske

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