Run-time error '1004': Document not saved.

kimseokjin

New Member
Joined
Feb 28, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Thanks in advance for your assistance. I keep getting error document not save with this VBA code. The debug code highlighted the following red text. Anyone know how to solve this?


Sub Crear_nuevo_fichero(temp_nombre_fichero, temp_directorio)
'
' Crear_nuevo_fichero con los datos del impreso actual
' Macro grabada el 19/11/2007 por NZBFRF
'
'
'
' Copiar hoja IMPRESO en un nuevo libro
'
Sheets("IMPRESO").Select
Sheets("IMPRESO").Copy
'
'---------------------------------------------------------------------
'
' Guardar el nuevo libro con el nombre del número de orden del impreso
'
'ChDir temp_directorio + "ORDENES"
ActiveWorkbook.SaveAs Filename:=temp_directorio + temp_nombre_fichero + ".xls", FileFormat:=xlOpenXMLWorkbook ', Password:="", WriteResPassword:=""
' ReadOnlyRecommended:=False, CreateBackup:=False
'----------------------------------------------------------------------
End Sub


Sub Abrir_fichero(nombre_fichero)
'
'Abrir fichero de la carpeta Ordenes
'
Excel.Application.Workbooks.Open Filename:=Range("rango_DIRECCION_CARPETA_BACKUP").Value + "ORDENES\" + nombre_fichero + ".xls"
Excel.Application.Visible = True
End Sub

Sub Activar_fichero(nombre_fichero)
Windows(nombre_fichero).Activate
End Sub


Thank you in advance.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Could be because you have a non-valid character in the variables temp_directorio and temp_nombre_fichero or a missing path separator. In debug mode put a stop at that line and when the macro stops there see what the value is of those two variable.
Then, the file extention .xls that you are using isn't compatible with FileFormat:=xlOpenXMLWorkbook which is for .xlsx.
 
Upvote 0
Thank you so much for the fast reply!

The original code was as below:


Sub Crear_nuevo_fichero(temp_nombre_fichero, temp_directorio)
'
' Crear_nuevo_fichero con los datos del impreso actual
' Macro grabada el 19/11/2007 por NZBFRF
'
'
'
' Copiar hoja IMPRESO en un nuevo libro
'
Sheets("IMPRESO").Select
Sheets("IMPRESO").Copy
'
'---------------------------------------------------------------------
'
' Guardar el nuevo libro con el nombre del número de orden del impreso
'
'ChDir temp_directorio + "ORDENES"
ActiveWorkbook.SaveAs Filename:=temp_directorio + temp_nombre_fichero + ".xls", FileFormat:=xlNormal ', Password:="", WriteResPassword:=""
' ReadOnlyRecommended:=False, CreateBackup:=False
'----------------------------------------------------------------------
End Sub


Sub Abrir_fichero(nombre_fichero)
'
'Abrir fichero de la carpeta Ordenes
'
Excel.Application.Workbooks.Open Filename:=Range("rango_DIRECCION_CARPETA_BACKUP").Value + "ORDENES\" + nombre_fichero + ".xls"
Excel.Application.Visible = True
End Sub

Sub Activar_fichero(nombre_fichero)
Windows(nombre_fichero).Activate
End Sub



I changed back to xlNormal. Can you please explain more on this "Could be because you have a non-valid character in the variables temp_directorio and temp_nombre_fichero or a missing path separator. In debug mode put a stop at that line and when the macro stops there see what the value is of those two variable."

I am still a newbie on VBA coding help T_T
 
Upvote 0
These two variables are passed as arguments of the macro: Sub Crear_nuevo_fichero(temp_nombre_fichero, temp_directorio) so what you need to know is what has been passed-on.
In your macro add this line of code just before:ActiveWorkbook.SaveAs Filename:=temp_directorio + temp_nombre_fichero + ".xls", FileFormat:=xlNormal , like this:
VBA Code:
'...
MsgBox temp_directorio & vbLf & temp_nombre_fichero
ActiveWorkbook.SaveAs Filename:=temp_directorio + temp_nombre_fichero + ".xls", FileFormat:=xlNormal
'...
and post the contents of the message box.
 
Upvote 0
Oh I see.

The temp_nombre_fichero refers to link of the document.
The temp_directorio refers to the order number.

Do you mean like this?

VBA Code:
Sub Crear_nuevo_fichero(temp_nombre_fichero, temp_directorio)
'
' Crear_nuevo_fichero con los datos del impreso actual
' Macro grabada el 19/11/2007 por NZBFRF
'
'
    '
    ' Copiar hoja IMPRESO en un nuevo libro
    '
    Sheets("IMPRESO").Select
    Sheets("IMPRESO").Copy
    '
    '---------------------------------------------------------------------
    '
    ' Guardar el nuevo libro con el nombre del número de orden del impreso
    '
    'ChDir temp_directorio + "ORDENES"
    MsgBox temp_directorio & vbLf & temp_nombre_fichero
    ActiveWorkbook.SaveAs Filename:=temp_directorio + temp_nombre_fichero + ".xls", FileFormat:=xlNormal ', Password:="", WriteResPassword:=""
    '    ReadOnlyRecommended:=False, CreateBackup:=False
    '----------------------------------------------------------------------
End Sub


Sub Abrir_fichero(nombre_fichero)
    '
    'Abrir fichero de la carpeta Ordenes
    '
    Excel.Application.Workbooks.Open Filename:=Range("rango_DIRECCION_CARPETA_BACKUP").Value + "ORDENES\" + nombre_fichero + ".xls"
    Excel.Application.Visible = True
End Sub

Sub Activar_fichero(nombre_fichero)
    Windows(nombre_fichero).Activate
End Sub
 
Upvote 0
Please run the macro and show the contents of the msgbox (as asked)
 
Last edited:
Upvote 0
1648549848163.png
 
Upvote 0
Sorry, maybe it's that can't explain myself, all I need is what the message box, I had you adding to your macro, says.
This other error you are now showing is self-explinating.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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