Saving workbooks in VBA

storemannequin

Board Regular
Joined
May 29, 2010
Messages
108
I keep getting an error when I'm trying to save each new workbook to the original/activeworkbooks file path. I don't see why:

Code:
Sub WeeklyNotification()

Application.ScreenUpdating = False

Set ActveWb = ActiveWorkbook
Set ActveWs = ActveWb.ActiveSheet

FnlRw = ActveWs.Cells(Rows.Count, 1).End(xlUp).Row
FnlCol = ActveWs.Cells(1, Columns.Count).End(xlToLeft).Column



For i = 2 To FnlRw
    With ActveWs.Cells(i, 1)
        ThisPln = ActveWs.Cells(i, 1).Value
        ThisNme = ActveWs.Cells(i, 2).Value

    Set SlsWb = Workbooks.Add(template:=xlWBATWorksheet)
    Set SlsWs = SlsWb.Worksheets(1)
    ActveWs.Range("A1").CurrentRegion.Rows(1).Copy Destination:=SlsWs.Range("A1")
    ActveWs.Cells(i, 1).Resize(, FnlCol).Copy Destination:=SlsWs.Cells(2, 1)
    SlsWs.Name = "UOM Diff"
    
    
    
   
   End With
   
    FN = ThisNme & " Discontinued Item List " & Date & ".xlsx"
    FP = ActveWb.Path & Application.PathSeparator
    
    SlsWb.SaveAs Filename:=FP & FN
    SlsWb.Close savechanges:=False
  
    
Next i

End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
I think the problem is this line:
Code:
    FN = ThisNme & " Discontinued Item List " & Date & ".xlsx"
"Date" returns slashes, which are not legal characters for file names. Try something like this instead:
Code:
    FN = ThisNme & "Discontinued Item List " & Format(Date,"mm-dd-yyyy") & ".xlsx"
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,874
Members
452,949
Latest member
Dupuhini

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