ファイルを、任意の名前をつけて、デスクトップに保存するVBAを紹介します。
![](https://ramq-cat.com/wp-content/uploads/2021/01/084919.jpg)
毎回毎回、毎日毎日、毎月毎月、同じ「作業」をするのは疲れますね。
ちょっとした、短時間の作業であってもそれは同じですね。
![](https://ramq-cat.com/wp-content/uploads/2021/01/098912.jpg)
![](https://ramq-cat.com/wp-content/uploads/2021/01/098912.jpg)
![](https://ramq-cat.com/wp-content/uploads/2021/01/098912.jpg)
そうそう。
ボタンをポチッと押したら完了すれば、ずいぶんストレスがへります。
![](https://ramq-cat.com/wp-content/uploads/2021/01/084919.jpg)
![](https://ramq-cat.com/wp-content/uploads/2021/01/084919.jpg)
![](https://ramq-cat.com/wp-content/uploads/2021/01/084919.jpg)
それならファイルの保存も「ポチッと」やっちゃいましょう。
![](https://ramq-cat.com/wp-content/uploads/2020/11/1484715_s.jpg)
![](https://ramq-cat.com/wp-content/uploads/2020/11/1484715_s.jpg)
デスクトップにファイルを保存するVBA
デスクトップにファイルを保存するVBA
Sub デスクトップに保存()
Dim strAa, strCa As String
Dim objNa As Object
Set objNa = CreateObject(“WScript.Network”)
strCa = objNa.UserName
strAa = InputBox(Prompt:=”ファイル名”)
ActiveWorkbook.SaveAs Filename:=”C:¥Users¥” & strCa & “¥Desktop¥” & strAa , FileFormat :=xlCSV, CreateBackup:=False
ActiveWindow.Close
End Sub
![](https://image.moshimo.com/af-img/0866/000000026029.jpg)
![](https://image.moshimo.com/af-img/0866/000000026029.jpg)
解説
デスクトップにあるフォルダ内を保存場所に指定する場合
フォルダ名を●●●とする。
Filename:=”C:¥Users¥” & strCa & “¥Desktop¥●●●¥” & strAa
ファイル名に特定の文字列を足して(可変+不変)保存する場合
不変のファイル名の文字列を▲▲とする。
Filename:=”C:¥Users¥” & strCa & “¥Desktop¥” & strAa & “▲▲”
ファイルの種類を指定する場合
よく使うファイルの種類を例に挙げます。
FileFormat :=xlCSV ’CSV
FileFormat :=xlOpenXMLWorkbook ’Excelブック
FileFormat :=xlOpenXMLWorkbookMacroEnabled ’Excelマクロ有効ブック
![](https://ramq-cat.com/wp-content/uploads/2020/08/5ba897d6d697425ab4b38f14e988b482.png)
![](https://ramq-cat.com/wp-content/uploads/2020/08/5ba897d6d697425ab4b38f14e988b482.png)
![](https://ramq-cat.com/wp-content/uploads/2020/08/5ba897d6d697425ab4b38f14e988b482.png)
デスクトップにファイルを保存するVBAでした。
![](https://ramq-cat.com/wp-content/uploads/2021/06/b4c174d21fbd7d840fc3ab9fd625fe46-1-300x157.png)
![](https://ramq-cat.com/wp-content/uploads/2021/06/b4c174d21fbd7d840fc3ab9fd625fe46-1-300x157.png)
コメント