run time error 1004

I

Ira

I have run time error 1004 while running a macro. It says Microsoft Office
Excel can not access the file. But file is there. Is anuthing wrong in the
code?
OutputFile = "C:\users\hz7fff\Desktop\Monthly Settlement\Monthly Output
Files\"

Report_Workbook = ActiveWorkbook.Name
If (Left(Report_Workbook, 11) = "Settlement ") Then

ActiveWorkbook.Names.Add Name:="Settlement_Data", RefersToR1C1:= _
"='Monthly Settlement Statement'!C1:C8"
ActiveWorkbook.Names.Add Name:="Copy_Row", RefersToR1C1:= _
"='Monthly Settlement Statement'!RC1,'Monthly Settlement
Statement'!RC2,'Monthly Settlement Statement'!RC4,'Monthly Settlement
Statement'!RC8"
Range("A1").Select
'
Message = "Enter the year and month for the data just processed in
YYYYMM format."
Title = "FileName"
Data_Date = InputBox(Message, Title)
'
Save_File = "Settlement " & Left(Data_Date, 4) & "-" & Right(Data_Date,
2) & ".xls"
Save_FullName = OutputFile & Save_File

''''''''''''''''''''''''''''''''''''''It stops here

ActiveWorkbook.SaveAs Filename:= _
Save_FullName, FileFormat:=xlNormal, Password:="",
WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
'''''''''''''''''''''''''''''''Please help!
 
P

Per Jessen

I have run time error 1004 while running a macro. It says Microsoft Office
Excel can not access the file. But file is there. Is anuthing wrong in the
code?
OutputFile = "C:\users\hz7fff\Desktop\Monthly Settlement\Monthly Output
Files\"

Report_Workbook = ActiveWorkbook.Name
If (Left(Report_Workbook, 11) = "Settlement ") Then

    ActiveWorkbook.Names.Add Name:="Settlement_Data", RefersToR1C1:= _
        "='Monthly Settlement Statement'!C1:C8"
    ActiveWorkbook.Names.Add Name:="Copy_Row", RefersToR1C1:= _
       "='Monthly Settlement Statement'!RC1,'Monthly Settlement
Statement'!RC2,'Monthly Settlement Statement'!RC4,'Monthly Settlement
Statement'!RC8"
    Range("A1").Select
'
    Message = "Enter the year and month for the data just processed in
YYYYMM format."
    Title = "FileName"
    Data_Date = InputBox(Message, Title)
'
    Save_File = "Settlement " & Left(Data_Date, 4) & "-" & Right(Data_Date,
2) & ".xls"
    Save_FullName = OutputFile & Save_File

''''''''''''''''''''''''''''''''''''''It stops here

    ActiveWorkbook.SaveAs Filename:= _
        Save_FullName, FileFormat:=xlNormal, Password:="",
WriteResPassword:="", _
        ReadOnlyRecommended:=False, CreateBackup:=False
'''''''''''''''''''''''''''''''Please help!

Hi

Check if the folder exists, I don't think it does.

Use the code below to test if OutputFile is a valid path.

OutputFile = "C:\users\hz7fff\Desktop\Monthly Settlement\Monthly
Output Files\"
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.folderexists(OutputFile) = False Then
msg = MsgBox("The folder do not exists", vbCritical)
Exit Sub
End If

Regards,
Per
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top