trying to save to a set location with a name that is set by cell value

Craig_Moore

Board Regular
Joined
Dec 12, 2018
Messages
64
Office Version
  1. 2019
Platform
  1. Windows
Hi All

I'm getting a run time error '1004': Application-defined or object-definer error but I cant see a reason for it any help would be much appreciated

Thanks

Craig


VBA Code:
Private Sub ARCHIVE_Click()


Dim Path As String
Dim filename As String
Path = "\\Duerrsfile\ss\01 PNB Production\OEE SHEETS\02. DOWN TIME SHEET\TOM'S ARCHIVED SHEETS\"
filename = Range("ARCHIVE_YEAR")

ActiveWorkbook.SaveAs filename:=Path & filename


End Sub
 

Attachments

  • save.jpg
    save.jpg
    156.8 KB · Views: 6

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Hi Craig,

VBA Code:
ActiveWorkbook.SaveAs filename:=Path & filename

where the first FileName stands for the path SaveAs expects and the second is your variable. Maybe try
VBA Code:
Private Sub ARCHIVE_Click()
Dim strPath         As String
Dim strFileName     As String

strPath = "\\Duerrsfile\ss\01 PNB Production\OEE SHEETS\02. DOWN TIME SHEET\TOM'S ARCHIVED SHEETS\"
strFileName = Range("ARCHIVE_YEAR")
'ARCHIVE_YEAR should hold something like Test.xlsm
'needed length is 5 characters like c.xls, change numbers to suit your needs
If Len(strFileName) < 5 Then
  MsgBox "Please check the filename and extension on Range 'ARCHIVE_YEAR'. ", vbInformation, "not enough characters..."
  Exit Sub
End If

If Dir(Left(strPath, Len(strPath) - 1), vbDirectory) <> vbNullString Then
  ActiveWorkbook.SaveAs filename:=strPath & strFileName, FileFormat:=52     '51 = xlsx, 52 = xlsm, 56 = xls
Else
  MsgBox "Please check the path to the Folder and run macro again.", vbExclamation, "File not saved"
End If

End Sub
Ciao,
Holger
 
Upvote 0
Hi thanks for replying,

I'm getting the MsgBox "Please check the path to the Folder and run macro again.

I have changed the file location to my c drive and the run time error stops so I'm guessing there may be an issue with the network file location causing the error but unsure why this would be an issue

thanks again for the help

Craig
 
Upvote 0
Hi Craig,

I'm sorry but I can't test with a network drive here. Should not be the drive being mapped and have been assigned to a letter like a "normal" drive on your computer (here is a link to a rather old thread, maybe the code may help with your problem: Map network drive using excel macro).

Ciao,
Holger
 
Upvote 0
No problem, Thanks for the help, the drive is mapped but I will have to check with my IT company if the same mapped address is used all all computers that use the document

Thanks again

Craig
 
Upvote 0

Forum statistics

Threads
1,214,924
Messages
6,122,294
Members
449,077
Latest member
Rkmenon

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