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.
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.