jamesmev

Board Regular
Joined
Apr 9, 2015
Messages
233
Office Version
  1. 365
Platform
  1. Windows
I am hoping someone can help me simplify this...
I have multiple tabs each I have a separate macro calling for each tab to be written to a directory in a shared network location.
I feel that this could be a lot cleaner...
Also I need it to not run copy the file over if J4 is blank on any of the tabs.
Any help would be appreciated.

Code:
Sub Macro7()
Application.ScreenUpdating = False
    Dim FolderPath As String, path As String, count As Integer
    FolderPath = "\\busines path\TCC\Workgroup\Location Site\Public\Winshuttle Downtime\Reyes"
    path = FolderPath & "\*.xlsx"
 
    Filename = Dir(path)
 
    Do While Filename <> ""
        count = count + 1
        Filename = Dir()
    Loop
     Application.DisplayAlerts = False
   Sheets("CombinedOE").Select
   Sheets("CombinedOE").Copy
    ChDir _
         FolderPath
    ActiveWorkbook.SaveAs Filename:= _
     FolderPath & "\" & Application.UserName & count & ".xlsx" _
        , FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
             Application.DisplayAlerts = False
    ActiveWorkbook.Close
    Call Macro8
        
          Application.DisplayAlerts = True
          Application.ScreenUpdating = True
End Sub
 
Sub Macro8()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
    Dim FolderPath As String, path As String, count As Integer
    FolderPath = "\\busines path\TCC\Workgroup\Location Site\Public\Winshuttle Downtime\CCBF"
    path = FolderPath & "\*.xlsx"
 
    Filename = Dir(path)
 
    Do While Filename <> ""
        count = count + 1
        Filename = Dir()
    Loop
     Application.DisplayAlerts = False
   Sheets("CombinedOEF").Select
   Sheets("CombinedOEF").Copy
    ChDir _
         FolderPath
    ActiveWorkbook.SaveAs Filename:= _
          FolderPath & "\" & Application.UserName & count & ".xlsx" _
        , FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
             Application.DisplayAlerts = False
    ActiveWorkbook.Close
    Call Macro9
Application.ScreenUpdating = False
Application.DisplayAlerts = False
End Sub
Sub Macro9()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
    Dim FolderPath As String, path As String, count As Integer
    FolderPath = "\\busines path\TCC\Workgroup\Location Site\Public\Winshuttle Downtime\Heartland"
    path = FolderPath & "\*.xlsx"
 
    Filename = Dir(path)
 
    Do While Filename <> ""
        count = count + 1
        Filename = Dir()
    Loop
     Application.DisplayAlerts = False
   Sheets("CombinedOEH").Select
   Sheets("CombinedOEH").Copy
    ChDir _
         FolderPath
    ActiveWorkbook.SaveAs Filename:= _
           FolderPath & "\" & Application.UserName & count & ".xlsx" _
        , FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
             Application.DisplayAlerts = False
    ActiveWorkbook.Close
   Call Macro10
Application.ScreenUpdating = False
Application.DisplayAlerts = False
End Sub
Sub Macro10()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
    Dim FolderPath As String, path As String, count As Integer
    FolderPath = "\\busines path\TCC\Workgroup\Location Site\Public\Winshuttle Downtime\Abarta"
    path = FolderPath & "\*.xlsx"
 
    Filename = Dir(path)
 
    Do While Filename <> ""
        count = count + 1
        Filename = Dir()
    Loop
     Application.DisplayAlerts = False
   Sheets("CombinedOEA").Select
   Sheets("CombinedOEA").Copy
    ChDir _
         FolderPath
    ActiveWorkbook.SaveAs Filename:= _
         FolderPath & "\" & Application.UserName & count & ".xlsx" _
        , FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
             Application.DisplayAlerts = False
    ActiveWorkbook.Close
    Call Macro11
Application.ScreenUpdating = False
Application.DisplayAlerts = False
End Sub
Sub Macro11()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
    Dim FolderPath As String, path As String, count As Integer
    FolderPath = "\\busines path\TCC\Workgroup\Location Site\Public\Winshuttle Downtime\Liberty"
    path = FolderPath & "\*.xlsx"
 
    Filename = Dir(path)
Application.DisplayAlerts = False
    Do While Filename <> ""
        count = count + 1
        Filename = Dir()
    Loop
     Application.DisplayAlerts = False
   Sheets("CombinedOEL").Select
   Sheets("CombinedOEL").Copy
    ChDir _
         FolderPath
    ActiveWorkbook.SaveAs Filename:= _
        FolderPath & "\" & Application.UserName & ".xlsx" _
        , FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
             Application.DisplayAlerts = False
    ActiveWorkbook.Close
    Call Macro12
Application.ScreenUpdating = False
Application.DisplayAlerts = False
End Sub
Sub Macro12()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
    Dim FolderPath As String, path As String, count As Integer
    FolderPath = "\\busines path\TCC\Workgroup\Location Site\Public\Winshuttle Downtime\Southwest"
    path = FolderPath & "\*.xlsx"
 
    Filename = Dir(path)
 
    Do While Filename <> ""
        count = count + 1
        Filename = Dir()
    Loop
     Application.DisplayAlerts = False
   Sheets("CombinedOESW").Select
   Sheets("CombinedOESW").Copy
    ChDir _
         FolderPath
    ActiveWorkbook.SaveAs Filename:= _
        FolderPath & "\" & Application.UserName & count & ".xlsx" _
        , FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
             Application.DisplayAlerts = False
    ActiveWorkbook.Close
    
         Call deleteinfo
          Application.DisplayAlerts = True
          Application.ScreenUpdating = True
End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
.
Code:
Option Explicit


Sub SplitWorkbook()
    Dim sDate As String
    Dim ws As Worksheet
    Dim wb1 As Workbook, wb2 As Workbook
    Dim sPath1 As String, sFile2 As String
    
    Application.ScreenUpdating = False
    
    Set wb1 = ThisWorkbook
    sPath1 = "\\busines path\TCC\Workgroup\Location Site\Public\Winshuttle Downtime\"
            
    For Each ws In wb1.Worksheets
        sFile2 = ws.Name
        ws.Copy
        Set wb2 = ActiveWorkbook
        
        On Error Resume Next
        Kill sPath1 & sFile2 & ".xlsx"
        On Error GoTo 0
        
        wb2.SaveAs Filename:=sPath1 & sFile2, FileFormat:=xlOpenXMLWorkbook
    
        wb2.Close (False)
    
        wb1.Activate
    
    Next


    Application.ScreenUpdating = True


End Sub

I am not familiar with network paths. I tested this using a path to my desktop and then again using a folder on my desktop and it works. Presuming your network path is accurate
it should work for you as is. If it doesn't, the only thing you should need to edit would be the line containing the path - nothing else.
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,256
Members
448,558
Latest member
aivin

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