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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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,215,327
Messages
6,124,294
Members
449,149
Latest member
mwdbActuary

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