save as macro help

Phil_Pearce

New Member
Joined
Feb 19, 2009
Messages
30
I have written the below code to save as all open workbooks apart from the workbook which contains the macro. It will save all the files including the macro workbook. What am i doing wrong?

Code:
Sub save_All()
    Dim wbk As Workbook
 
    Application.ScreenUpdating = False
 
    For Each wbk In Workbooks
        If wbk.Name <> "macro.XLS" Then
            Debug.Print wbk.Name
 
               With wbk
                .SaveAs Filename:="N:\Invest\Shared\test\transfer " & wbk.Name & ".csv"
                End With
        End If
    Next wbk
 
    Application.ScreenUpdating = True
 
End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Your macro workbook is definitely called macro.xls?

In any case I would consider using

Rich (BB code):
If wbk.Name <> ThisWorkbook.Name Then

also, don't you need to have

Rich (BB code):
.SaveAs Filename:="N:\Invest\Shared\test\transfer " & wbk.Name & ".csv",  FileFormat:=xlCSV

And I guess you'll get an odd file name, since wbk.Name will include the existing file extension, so it'll be called "transfer Book1.xls.csv"

Maybe
Rich (BB code):
Left(wbk.Name,=Iinstr(1,wbk.Name,".")-1)
would get around that one?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,196,120
Messages
6,013,578
Members
441,774
Latest member
esandoval

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