Save Multiple Active Workbooks

temerson

New Member
Joined
Apr 22, 2019
Messages
39
Hello,

I have the following code:

Sub VisibleSheets(Optional ByVal Control As IRibbonControl)
On Error Resume Next


Dim ws As Worksheet
Dim wbNew As Workbook
Dim WSHShell As Object
Dim DesktopPath As String
Dim VendorName As String
Dim StoreName As String


VendorName = Range("I2")
StoreName = Range("J2")


Set WSHShell = CreateObject("WScript.Shell")
DesktopPath = WSHShell.SpecialFolders("Desktop")

For Each ws In ActiveWorkbook.Sheets
If ws.Visible Then
Debug.Print "Exporting: " & ws.Name
ws.Copy
Set wbNew = Application.ActiveWorkbook

Set wbNew = Nothing


DesktopPath = WSHShell.SpecialFolders("Desktop")
ActiveWorkbook.SaveAs DesktopPath & "\#" & StoreName & " OPENING DAIRY ORDER-" & VendorName & ".xls"


End If
Next ws

Set ws = Nothing
Set WSHShell = Nothing


End Sub

The end goal is to have each tab in the workbook have its own workbook, then save it onto my desktop. The problem I am facing is after the first workbook is saved, the proceeding active workbooks fail to save.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Change your code to the following macro.

Code:
Sub Save_Multiple_Workbooks()
  Dim ws As Worksheet, wbNew As Workbook, DPath As String, VendorN As String, StoreN As String
  Application.ScreenUpdating = False
  Application.DisplayAlerts = False
  DPath = CreateObject("WScript.Shell").SpecialFolders("Desktop")
  For Each ws In ThisWorkbook.Sheets
    If ws.Visible Then
      VendorN = ws.Range("I2")
      StoreN = ws.Range("J2")
      ws.Copy
      Set wbNew = ActiveWorkbook
      wbNew.SaveAs DPath & "\#" & StoreN & " OPENING DAIRY ORDER-" & VendorN & ".xls"
      wbNew.Close False
    End If
  Next ws
  Set ws = Nothing
End Sub
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,709
Messages
6,126,391
Members
449,311
Latest member
accessbob

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