VBA SaveAs issue

storemannequin

Board Regular
Joined
May 29, 2010
Messages
108
I'm trying to save this new workbook to the original workbooks filepath location but when I run the code I get an alert saying that there is already a file of the same name/path saved in my folder and asks would you like to replace - which when I click yes, nothing happens. I'm guessing something is wrong with the code here because I checked before running the macro if there was the same filename I deleted. I hightlighted in red the part not working.

Rich (BB code):
Sub FDD()
Dim WBO As Workbook, WBD As Workbook
Dim WSO As Worksheet, WSD As Worksheet
Dim i As Long, FR As Long, FC As Long
 
FR = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
FC = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
 
Set WBO = ActiveWorkbook
Set WSO = ActiveSheet
 
Set WBD = Workbooks.Add(template:=xlWBATWorksheet)
Set WSD = WBD.Worksheets(1)
 
Application.ScreenUpdating = False
 
WSO.Range("A1").CurrentRegion.Rows(1).Copy Destination:=WSD.Range("A1")
WSD.Name = "Danaher Master"
 
nextrow = 2
 
For i = FR To 2 Step -1
 
    If StrComp(CStr(WSO.Cells(i, 2)), "DEXIS ") = 0 Then
        WSO.Cells(i, 1).Resize(, FC).Copy Destination:=WSD.Cells(nextrow, 1)
        WSO.Rows(i).EntireRow.Delete
        nextrow = nextrow + 1
    ElseIf StrComp(CStr(WSO.Cells(i, 2)), "GENDEX") = 0 Then
        WSO.Cells(i, 1).Resize(, FC).Copy Destination:=WSD.Cells(nextrow, 1)
        WSO.Rows(i).EntireRow.Delete
        nextrow = nextrow + 1
    ElseIf StrComp(CStr(WSO.Cells(i, 2)), "KAVO  ") = 0 Then
        WSO.Cells(i, 1).Resize(, FC).Copy Destination:=WSD.Cells(nextrow, 1)
        WSO.Rows(i).EntireRow.Delete
        nextrow = nextrow + 1
    ElseIf StrComp(CStr(WSO.Cells(i, 2)), "P&C   ") = 0 Then
        WSO.Cells(i, 1).Resize(, FC).Copy Destination:=WSD.Cells(nextrow, 1)
        WSO.Rows(i).EntireRow.Delete
        nextrow = nextrow + 1
    ElseIf StrComp(CStr(WSO.Cells(i, 2)), "IMGSCI") = 0 Then
        WSO.Cells(i, 1).Resize(, FC).Copy Destination:=WSD.Cells(nextrow, 1)
        WSO.Rows(i).EntireRow.Delete
        nextrow = nextrow + 1
    End If
 
   FN = "this" & ".xlsx"
 FP = WBO.Path & Application.PathSeparator
 
 WBD.SaveAs Filename:=FP & FN
 
 
 
 
 
Next i
End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
I had a similar problem with a spreadsheet that I have update automatically every day...

What I did was save as the file name with a timestamp after the file name then I go through from time to time and delete any old files.

i used something like this...

Code:
Sub filesave()
ActiveWorkbook.SaveAs Filename:="[URL="file://\\munchkin\products$\Monthly"]File Name here[/URL] " & _
  Format(Now(), "mm_dd_yyyy hh mm AMPM"), FileFormat:=xlOpenXMLWorkbookMacroEnabled, Password:="", _
  WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False
End Sub

Not sure if that will help but just thought I'd add my $.02
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,828
Members
452,946
Latest member
JoseDavid

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