VBA - Save Specific Sheets as New Workbooks with File name corresponding to C5 from each sheet.

AndrewDrewAndy

New Member
Joined
Nov 18, 2019
Messages
16
I have a workbook with 10 active files, but I only need to save sheets ("Export 1", "Export 2", "Export 3", "Export 4", "Export 5"). I have a file path I want to save them in, but I cannot find a code to save each sheets filename to the .txt in each sheets' C5 cell (each sheet has a different person's name that the file needs to be saved as). It doesn't work to change the worksheet names because the file is active and changes ofte
 
How about
VBA Code:
Sub AndrewDrew()
    Dim Ary As Variant
    Dim i As Long
    Dim Pth As String
   
    Pth = Sheets("Master Data").Range("A1")
    If Not Right(Pth, 1) = "\" Then Pth = Pth & "\"
    Ary = Array("Export 1", "Export 2", "Export 4")
    For i = 0 To UBound(Ary)
        Sheets(Ary(i)).Copy
        With ActiveWorkbook
            .SaveAs Pth & Range("C5").Value, 51
            .Close False
        End With
    Next i
End Sub

This is great. I am just learning that file paths for desktop and mac are much different. Is there a way to build in for the vba to save to either Mac or Desktop depending on which is running the excel.

Again, I am very appreciative of your help.
 
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Yes that's possible, but I know nothing about Macs, or their path structure, so cannot help further.
 
Upvote 0

Forum statistics

Threads
1,216,326
Messages
6,130,054
Members
449,555
Latest member
maXam

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