Save Different Worksheets To Different Paths VBA

leewoo5

New Member
Joined
Feb 5, 2017
Messages
13
Hi,

I have 2 pieces of code I would like to put into one so that 2 of the worksheets save in one folder, whilst the other saves in a different folder.
Problem is, I would like to run this from one button and it doesn't work running both of these from the same button.

Code as follows:

Code:
Sub SaveAsClosed() 
  Dim fName As String
  Dim sLoc As String  'location
 
  sLoc = "I:\FST\Quality\Non-Conformance\Non-Conformance Reports\Open\Closed\"
 
  ' Select both sheets to export into PDF file
  Sheets(Array("NCR", "RCA")).Select
 
  With ActiveSheet
   
    fName = .Range("L4").Value & "C" & "-" & .Range("E6").Value
 
    'Save as xlsm
    ActiveWorkbook.SaveAs Filename:=sLoc & fName, FileFormat:=xlOpenXMLWorkbookMacroEnabled
   
    ' Export to the PDF
    .ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
                         sLoc & fName, Quality:=xlQualityStandard, _
                         IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
   
    ' Unselect the group (select only one sheet)
    .Select
 
  End With
 
End Sub












Sub SaveCustomerCopyClosed()
 
  Dim fName As String
  Dim sLoc As String  'location
 
  sLoc = "I:\FST\Quality\Non-Conformance\Non-Conformance Reports\Customer Copy Non-Conformance Report\"
 
  ' Select both sheets to export into PDF file
  Sheets(Array("CUSTOMER COPY")).Select
 
  With ActiveSheet
   
    fName = .Range("L4").Value & "C" & "-" & .Range("E6").Value
 
    'Save as xlsm
    ActiveWorkbook.SaveAs Filename:=sLoc & fName, FileFormat:=xlOpenXMLWorkbookMacroEnabled
   
    ' Export to the PDF
    .ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
                         sLoc & fName, Quality:=xlQualityStandard, _
                         IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
   
    ' Unselect the group (select only one sheet)
    .Select
 
  End With
End Sub

Many thanks,
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Hi,

I have 2 pieces of code I would like to put into one so that 2 of the worksheets save in one folder, whilst the other saves in a different folder.
Problem is, I would like to run this from one button and it doesn't work running both of these from the same button.

Code as follows:

Code:
Sub SaveAsClosed() 
  Dim fName As String
  Dim sLoc As String  'location
 
  sLoc = "I:\FST\Quality\Non-Conformance\Non-Conformance Reports\Open\Closed\"
 
  ' Select both sheets to export into PDF file
  Sheets(Array("NCR", "RCA")).Select
 
  With ActiveSheet
   
    fName = .Range("L4").Value & "C" & "-" & .Range("E6").Value
 
    'Save as xlsm
    ActiveWorkbook.SaveAs Filename:=sLoc & fName, FileFormat:=xlOpenXMLWorkbookMacroEnabled
   
    ' Export to the PDF
    .ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
                         sLoc & fName, Quality:=xlQualityStandard, _
                         IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
   
    ' Unselect the group (select only one sheet)
    .Select
 
  End With
 
End Sub

Sub SaveCustomerCopyClosed()
 
  Dim fName As String
  Dim sLoc As String  'location
 
  sLoc = "I:\FST\Quality\Non-Conformance\Non-Conformance Reports\Customer Copy Non-Conformance Report\"
 
  ' Select both sheets to export into PDF file
  Sheets(Array("CUSTOMER COPY")).Select
 
  With ActiveSheet
   
    fName = .Range("L4").Value & "C" & "-" & .Range("E6").Value
 
    'Save as xlsm
    ActiveWorkbook.SaveAs Filename:=sLoc & fName, FileFormat:=xlOpenXMLWorkbookMacroEnabled
   
    ' Export to the PDF
    .ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
                         sLoc & fName, Quality:=xlQualityStandard, _
                         IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
   
    ' Unselect the group (select only one sheet)
    .Select
 
  End With
End Sub

Many thanks,

Just insert the function name before end sub.

Sub SaveAsClosed()
Dim fName As String
Dim sLoc As String 'location

sLoc = "I:\FST\Quality\Non-Conformance\Non-Conformance Reports\Open\Closed"

' Select both sheets to export into PDF file
Sheets(Array("NCR", "RCA")).Select

With ActiveSheet

fName = .Range("L4").Value & "C" & "-" & .Range("E6").Value

'Save as xlsm
ActiveWorkbook.SaveAs Filename:=sLoc & fName, FileFormat:=xlOpenXMLWorkbookMacroEnabled

' Export to the PDF
.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
sLoc & fName, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True

' Unselect the group (select only one sheet)
.Select
End With

call SaveCustomerCopyClosed

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,900
Messages
6,175,276
Members
452,629
Latest member
SahilPolekar

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