如何保存到当前User\Desktop位置 [英] How to save to current User\Desktop location

查看:177
本文介绍了如何保存到当前User\Desktop位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图将一个excel工作表保存为.PRN文件到当前的用户桌面。我想也许有一个标准的通配符操作符,我可以使用,但我看不到任何地方。我已经看过堆栈溢出,我发现可能是我正在寻找的信息,但是由于我不是一个程序员,而且不是很好的excel,我不知道是否是我想要的,如果是,在哪里放在我的代码。

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?

推荐答案

虽然roryap的解决方案是非常好的,工作,我想添加另一个工作解决方案

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

这篇关于如何保存到当前User\Desktop位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆