View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rob van Gelder[_4_] Rob van Gelder[_4_] is offline
external usenet poster
 
Posts: 1,236
Default ThisWorkbook.SaveAs not saving correctly

Try something like:

ThisWorkbook.SaveAs Filename:=fMyDocs & fName

Where fMyDocs might be initialised as:
fMyDocs = Range("m2").Value 'cell M2 = C:\Documents and
Settings\MyUserName\My Documents\
or
fMyDocs = Environ("USERPROFILE") & Application.PathSeparator & "My
Documents" & Application.PathSeparator



--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Ron" wrote in message
10.130...
Hi guys,

Once again I ask for assistance, however I'm getting much better at this
vba. Just not that good yet ;)

Anyway, I'm writing an invoice for my nephew [electrical contractor]
with a macro in that will automatically save the workbook with a new
name.

He opens a blank template and when he's filled in the details he hits
the save macro button and the file should save as a new book with a
unique filename generated from his invoice number joined with the first
4 letters of his customers surname.

The code I've used is..

Sub SaveUnique()
Dim fName As String
fName = Range("m3").Value
ThisWorkbook.SaveAs Filename:=fName
End Sub

Pretty simple looking and it did actually save the first couple in the
same folder as the template.

However it now wants to only save in My Documents. The folder it should
be saving in is MyDocuments\invoices.

If I open the template from the folder MyDocuments\invoices it saves to
My Documents only now, after having initially saved to the correct
folder twice.

The vba help states that the SaveAs method save to the current folder,
but it's not happening for me.

Any Ideas?

Regards,

Ron