error 1004 while saving worksheet

Hans810

Board Regular
Joined
Dec 1, 2005
Messages
63
Dear All,

Using VBA code as given below, I get an error message (error 1004, Method SaveAs of object_Workbook failed) while saving the second worksheet (marked with *** behind the code line).
It seems it has to do with saving twice in a row from the same Workbook.
At least that is what I have read on the MS site.

Any idea how to solve this or how to make a workaround?

Any help is appreciated.

Regards from The Netherlands


VBA Code START
Sub Save()

Sheets("Data").Select
locatie1 = (Range("O3").Value)
'locatie1=C:\Uren\Reguliere uren
Sheets("Import 1").Select
Application.DisplayAlerts = False
ActiveSheet.Copy
Columns(1).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
ActiveWorkbook.SaveAs locatie1, xlTextWindows
ActiveWorkbook.Close
Application.DisplayAlerts = True

Sheets("Data").Select
locatie2 = (Range("O4").Value)
'locatie2 = "C:\Uren\Reguliere uren\Reguliere uren "&Gegevens!E1&"-"&Gegevens!C1&".txt"
Sheets("Gegevens").Select
Application.DisplayAlerts = False
ActiveSheet.Copy
Columns(1).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
ActiveWorkbook.SaveAs locatie2, xlTextWindows ***
ActiveWorkbook.Close
Application.DisplayAlerts = True
Sheets("Import 1").Select
Range("A1").Select
End Sub

VBA Code END
 
What's the value of locatie2 when you get the error?
 
Upvote 0
That line is commented out, this is the line that sets the value of locatie2.
Rich (BB code):
locatie2 = (Range("O4").Value)

Even if that line wasn't commented I don't think it would work.

The reason I say that is that the highlighted parts below appear to be cell references but VBA wouldn't see them as such.
Rich (BB code):
'locatie2 = "C:\Uren\Reguliere uren\Reguliere uren "&Gegevens!E1&"-"&Gegevens!C1&".txt"

Where are you actually trying to get the filename from?
 
Upvote 0
from a worksheet with all the variables.
The funny thing is that the first one works!
And I have this problem only on one computer....very strange.
 
Upvote 0
Have you checked the value of locatie2 when you get the error?
 
Last edited:
Upvote 0
: locatie2 : "C:\Uren\Reguliere uren\Reguliere uren Juni-15.txt" : Variant/String

that is what I get when the error occurs. (from local variables)
 
Upvote 0
Hi Norie,

I found the solution: there was a spelling error in the destination path ..........so silly.

Anyway thanks for your help. At least your comment forced me to rechecking the spelling.

Have a nice day.
 
Upvote 0

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