Save File Macro ERROR

nathanpeattie

New Member
Joined
Dec 17, 2005
Messages
43
this is my code

Sub macro1()

FileID = InputBox("Type The PO Number To Be Saved")
ActiveWorkbook.SaveAs Filename:= _
"C:\Montford\Quotes\Customers\" & FileID & ".xls", FileFormat _
:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

End Sub

if I click cancel in the diaglog box it get

Runtime Error "1004"

Method 'SaveAs' of object '_Workbook' Failed

and I get End And Debug (How to fix?)

Thanks
 

Some videos you may like

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,086
Office Version
  1. 365
Platform
  1. Windows
Perhaps this.
Code:
Sub macro1() 

FileID = InputBox("Type The PO Number To Be Saved") 
If FileID<>"" Then
     ActiveWorkbook.SaveAs Filename:= _ 
"C:\Montford\Quotes\Customers\" & FileID & ".xls"
End If
End Sub
 

nathanpeattie

New Member
Joined
Dec 17, 2005
Messages
43
Thanks that worked great.

The next thing I need is a find code. As you can see I save the workbook as a PO number eg: 12345.xls I need a code that when I click a button it will find PO number files.

EG: A dialog box will open and ask the user to type in the PO number they want to find. The user will input the po number and click ok. The code will then find the file with the po number and open it.

All the files will be in the same location I will not need the code to search the whole drive just 1 location.

Thanks
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,086
Office Version
  1. 365
Platform
  1. Windows
nathan

Could you please try and keep to one thread?

As far as I can see all your posts so far are related.
 

nathanpeattie

New Member
Joined
Dec 17, 2005
Messages
43

ADVERTISEMENT

Sorry can you help on the find file code?

Thanks
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,086
Office Version
  1. 365
Platform
  1. Windows
Yes I probably can, but I seem to remember that in another thread somebody has made some suggestions.

Like I said try and keep to 1 thread.

I've read most of your posts and have now become confused as to what stage you are currently at.

Are you not getting a bit confused yourself?:)
 

nathanpeattie

New Member
Joined
Dec 17, 2005
Messages
43

ADVERTISEMENT

I have read those suggestions and I have one of them as my open origanl file code.

The find code is the last code I am working on and then the project to done.

If I have missed a suggestion can you post the location of that post

Thanks
 

SDSU_Jim

Board Regular
Joined
Nov 29, 2005
Messages
127
Try this:
====================================
Sub GetFile()
NewFN = Application.GetOpenFilename(filefilter:="Text Files(*.xls),*.xls,All Files (*.*),*.*", Title:="Please select a file")
If NewFN = False Then
' They pressed Cancel
MsgBox "Stopping because you did not select a file"
Exit Sub
Else
Workbooks.Open Filename:=NewFN
End If
End Sub
===================================
It won't "Search" for a PO #, but since they know the PO # and have saved the file with that name, typing the PO # in the file Name section in the "Open" dialog will open that file.
 

Watch MrExcel Video

Forum statistics

Threads
1,119,128
Messages
5,576,261
Members
412,709
Latest member
Rishu
Top