So I am trying to save an excel worksheet as a .PRN file to the current users desktop. I thought maybe there was a standard "wildcard" operator that I could use, but I don't see that anywhere. I have looked through stack overflow and I found information that is probably what I am looking for, but due to me not being a programmer and not very good with excel, I don't know if it is what I want and if it is, where to put it in my code.
This is what I am currently running that only works on my machine:
Sub Save_PRN()
Dim fileName As String
fileName = "C:\Users\cameron\Desktop\PRN Test files\" & Range("'Customer_Info'!R2").Text & ".prn"
ActiveWorkbook.SaveAs fileName:=fileName, FileFormat:=xlTextPrinter, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False
End Sub
While it does what I want, when I upload it to our share, clearly another user won't be able to use it. I saw on a question someone answered stating to use this:
MsgBox CreateObject("WScript.Shell").specialfolders("Desktop")
But I don't know or understand how to incorporate that into my macro above. Any help or advice would be great. Am I even on the right track?
While roryap's solution is perfectly fine and working, I would like to add another working solution.
Dim strPath as String
strFileName = Environ("USERPROFILE") & "\Desktop\PRN Test files\" & Range("'Customer_Info'!R2").Text & ".prn"
ActiveWorkbook.SaveAs fileName:=strFileName, FileFormat:=xlTextPrinter, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False
You can use it like this:
Dim desktopFolderPath As String
desktopFolderPath = CreateObject("WScript.Shell").specialfolders("Desktop")
fileName = desktopFolderPath & "\PRN Test files\" & Range("'Customer_Info'!R2").Text & ".prn"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With