VBA - Exporting 2 different sheets to 2 different locations

johnny51981

Active Member
Joined
Jun 8, 2015
Messages
366
My VBA knowledge, at this time, is basically plagiarism or crying for help.

I have a single workbook that I am needing to export 2 of its sheets to 2 different locations. At least that is the hope, rather than having to do the movement manually as I am trying to save every second I can in my workday.

ExportActiveTask is currently exporting to the same location as the source workbook, which is fine.
ExportGoalECCD is to be exported to a specific network location, which I have created a Named Range with the full path. Named Range is "GoalECCD".

When I run the macros, they both go to the same location, being the ThisWorkbook.Path, even though the ExportGoalECCD has that line of code deactivated.

Any help at getting these to part ways rather than maintaining their codependency would be greatly appreciated.

My current code
VBA Code:
Sub ExportActiveTask()
    Application.ScreenUpdating = False

    ChDir ThisWorkbook.Path
    Application.DisplayAlerts = False

    ThisWorkbook.Sheets("TASK DATA").Copy
    ActiveWorkbook.SaveAs Filename:="Active Tasks.CSV", FileFormat:=xlCSV, CreateBackup:=False
    ActiveWorkbook.Close

MsgBox "Active Task file export is now complete"
End Sub
Sub ExportGoalECCD()
    Application.ScreenUpdating = False

    'ChDir ThisWorkbook.Path
    ChDir Range("GoalECCD")
    Application.DisplayAlerts = False

    ThisWorkbook.Sheets("GOAL ECCD").Copy
    ActiveWorkbook.SaveAs Filename:="Goal ECCD by Job.CSV", FileFormat:=xlCSV, CreateBackup:=False
    ActiveWorkbook.Close
    
MsgBox "Goal ECCD by Job file export is now complete"

End Sub

Thanks in advance!
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
See whether this helps ...

VBA Code:
Sub ExportActiveTask()

    Application.ScreenUpdating = False
    Application.DisplayAlerts = False

    Dim TargetFolder As String
    TargetFolder = ThisWorkbook.Path & "\"

    ThisWorkbook.Sheets("TASK DATA").Copy
    ActiveWorkbook.SaveAs Filename:=TargetFolder & "Active Tasks.CSV", FileFormat:=xlCSV, CreateBackup:=False
    ActiveWorkbook.Close

    MsgBox "Active Task file export is now complete"
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
End Sub

Sub ExportGoalECCD()

    Application.ScreenUpdating = False
    Application.DisplayAlerts = False

    Dim TargetFolder As String
    TargetFolder = Range("GoalECCD") & "\"

    ThisWorkbook.Sheets("GOAL ECCD").Copy
    ActiveWorkbook.SaveAs Filename:=TargetFolder & "Goal ECCD by Job.CSV", FileFormat:=xlCSV, CreateBackup:=False
    ActiveWorkbook.Close

    MsgBox "Goal ECCD by Job file export is now complete"
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True

End Sub
 
Upvote 0
Solution
You are welcome and thanks for the feedback (y)
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,678
Members
449,116
Latest member
HypnoFant

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