VBA save sheet to folder

ceytl

Board Regular
Joined
Jun 6, 2009
Messages
114
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I have a VBA script that saves my active workbook into a folder called S1, but I want to change it to only to save a worksheet named Order1 to the same S1 folder.

I also don't want the original workbook to close, only the one I just saved.

Any help would be appreciated.

Sub SaveMe()

Dim filename101 As String
Dim path101 As String
Dim fso As Object

Application.DisplayAlerts = False

Set fso = CreateObject("Scripting.FileSystemObject")


path101 = Environ("UserProfile") & "\Orders\S1\"

If Not fso.FolderExists(path101) Then
MsgBox "The folder " & path101 & " doesn't exist.", vbExclamation
Exit Sub
End If

filename101 = "Order1 " & Range("B5").Value & ".xlsx"

ActiveWorkbook.SaveAs path101 & filename101, xlOpenXMLWorkbook
Application.DisplayAlerts = True

End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
is this what you are trying to do
VBA Code:
Sub SaveActiveSheet_as_Woorkbook1()
Dim wb As Workbook

    ActiveSheet.Copy
    Set wb = ActiveWorkbook

    wb.SaveAs Environ("UserProfile") & "\Orders\S1\" & ActiveSheet.Name, FileFormat:=xlWorkbookNormal
    wb.Close


End Sub
 
Upvote 0
Solution
is this what you are trying to do
VBA Code:
Sub SaveActiveSheet_as_Woorkbook1()
Dim wb As Workbook

    ActiveSheet.Copy
    Set wb = ActiveWorkbook

    wb.SaveAs Environ("UserProfile") & "\Orders\S1\" & ActiveSheet.Name, FileFormat:=xlWorkbookNormal
    wb.Close


End Sub

Thanks!

I modified it to save the worksheet I wanted, and change the format to .xlsx

Sub SaveActiveSheet_as_Woorkbook2()

Dim wb As Workbook

Worksheets("S2").Copy
Set wb = ActiveWorkbook
wb.SaveAs Environ("UserProfile") & "\Desktop\2022 spring booking orders\S2\" & "Order1 " & Range("B5").Value, FileFormat:=xlOpenXMLWorkbook
wb.Close

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,550
Members
449,088
Latest member
davidcom

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