Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default file name as specified cell when save as or save is clicked

Can someone help me? I have a document I have created in MSExcel. It is
being used by multiple users. I would like them to be able to have them
access the form, fill in the information and then when they go to save it
have the default save as filename be a specified cell value from the
spreadsheet. I have written code that does the filename as specified value
but I can only get it to run when I Run Code from VBA or when I choose
MacroRun. Or I can get it to loop consistently on file open. I want it to
run when the user clicks save or saveas. Thanks for your help.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default file name as specified cell when save as or save is clicked

I should have added the code i have writen so far:


Sub save_as()
savedir = Sheets("No Problem Found Report").Range("F10").Value
fname = Sheets("No Problem Found Report").Range("F10").Value
Application.Dialogs(xlDialogSaveAs).Show ("c:\" & savedir & "\" & fname)
End Sub



"lynn" wrote:

Can someone help me? I have a document I have created in MSExcel. It is
being used by multiple users. I would like them to be able to have them
access the form, fill in the information and then when they go to save it
have the default save as filename be a specified cell value from the
spreadsheet. I have written code that does the filename as specified value
but I can only get it to run when I Run Code from VBA or when I choose
MacroRun. Or I can get it to loop consistently on file open. I want it to
run when the user clicks save or saveas. Thanks for your help.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 411
Default file name as specified cell when save as or save is clicked

Would either of these work?




From: "Ron de Bruin"
Date: Wed, 27 Sep 2006 16:53:02 +0200
Local: Wed, Sep 27 2006 6:53 am
Subject: Changing default Save As name to a cell location.

Hi gtslabs

You can use GetSaveAsFilename
I use the value of Sheets("Sheet1").Range("A1").Value

Sub Test()
Dim fname As Variant
fname = Application.GetSaveAsFilename(Sheets("Sheet1").Ran ge
("A1").Value, _
fileFilter:="Excel Files
(*.xls), *.xls")
If fname < False Then
ActiveWorkbook.SaveAs fname
Else
'do nothing
End If
End Sub

--
Regards Ron de Bruin
http://www.rondebruin.nl



From: "moon"
Date: Wed, 27 Sep 2006 17:01:43 +0200
Local: Wed, Sep 27 2006 7:01 am
Subject: Changing default Save As name to a cell location.

An alternative is to trigger the Save-event, which doesn't require an
extra
mouse-click which launches a sub...

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)

Dim fileName As String

'Don't do this on Save, only on SaveAs
If SaveAsUI = True Then

'Grab filename from Cell A1
fileName = ActiveSheet.Cells(1, 1).Value

'What if they forgot the extension?
If Right(fileName, 4) < ".xls" Then fileName = fileName &
".xls"

'The TextBox for the filename in the dialog
'is already highlighted (selected) so all
'you have to do is send the filename
Application.SendKeys fileName

End If

End Sub

"Ron de Bruin" schreef in bericht
...

From: "gtslabs"
Date: 27 Sep 2006 08:26:33 -0700
Local: Wed, Sep 27 2006 7:26 am
Subject: Changing default Save As name to a cell location.

This is what I need thanks, but I can not get it to launch. Where
would
it go? in a separate module or the worksheet code? I tried both with
no luck.

Thanks
Steven
From: "moon"
Date: Wed, 27 Sep 2006 18:03:23 +0200
Local: Wed, Sep 27 2006 8:03 am
Subject: Changing default Save As name to a cell location.

Sorry for not mentioning that.
It should be in the Workbook-code.
Double click on ThisWorkbook to end up there.

"gtslabs" schreef in bericht
ps.com...
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default file name as specified cell when save as or save is clicked

I am getting an error on this portion of the script:

fname =
Application.GetSaveAsFilename(Sheets("NoProblemFou ndReport").Range("F10").Value, _
fileFilter:="Excel Files"
(*.xls), *.xls")

On the second option I am getting an error on this portion -

If Right(fileName, 4) < ".xls" Then fileName = fileName &
".xls"

So I don't know if either would work, however, I think I probably do want it
to run if save is clicked, the problem is, I have technician's using my form
that are not careful about the file name and keep saving over the original.
They need to be spoon fed so they can't screw it up.


"dan dungan" wrote:

Would either of these work?




From: "Ron de Bruin"
Date: Wed, 27 Sep 2006 16:53:02 +0200
Local: Wed, Sep 27 2006 6:53 am
Subject: Changing default Save As name to a cell location.

Hi gtslabs

You can use GetSaveAsFilename
I use the value of Sheets("Sheet1").Range("A1").Value

Sub Test()
Dim fname As Variant
fname = Application.GetSaveAsFilename(Sheets("Sheet1").Ran ge
("A1").Value, _
fileFilter:="Excel Files
(*.xls), *.xls")
If fname < False Then
ActiveWorkbook.SaveAs fname
Else
'do nothing
End If
End Sub

--
Regards Ron de Bruin
http://www.rondebruin.nl



From: "moon"
Date: Wed, 27 Sep 2006 17:01:43 +0200
Local: Wed, Sep 27 2006 7:01 am
Subject: Changing default Save As name to a cell location.

An alternative is to trigger the Save-event, which doesn't require an
extra
mouse-click which launches a sub...

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)

Dim fileName As String

'Don't do this on Save, only on SaveAs
If SaveAsUI = True Then

'Grab filename from Cell A1
fileName = ActiveSheet.Cells(1, 1).Value

'What if they forgot the extension?
If Right(fileName, 4) < ".xls" Then fileName = fileName &
".xls"

'The TextBox for the filename in the dialog
'is already highlighted (selected) so all
'you have to do is send the filename
Application.SendKeys fileName

End If

End Sub

"Ron de Bruin" schreef in bericht
...

From: "gtslabs"
Date: 27 Sep 2006 08:26:33 -0700
Local: Wed, Sep 27 2006 7:26 am
Subject: Changing default Save As name to a cell location.

This is what I need thanks, but I can not get it to launch. Where
would
it go? in a separate module or the worksheet code? I tried both with
no luck.

Thanks
Steven
From: "moon"
Date: Wed, 27 Sep 2006 18:03:23 +0200
Local: Wed, Sep 27 2006 8:03 am
Subject: Changing default Save As name to a cell location.

Sorry for not mentioning that.
It should be in the Workbook-code.
Double click on ThisWorkbook to end up there.

"gtslabs" schreef in bericht
ps.com...

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 411
Default file name as specified cell when save as or save is clicked

What error are you getting?


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default file name as specified cell when save as or save is clicked

The script I noted was red and before I even ran it I got the messages
Compile error: Expected: line number or label or statement or end of
statement. I was using a simpler code, that worked, I just need to know how
to activate it upon clicking the save as or save buttons:

This is the code that performs the function

Sub save_as()
savedir = Sheets("No Problem Found Report").Range("F10").Value
fname = Sheets("No Problem Found Report").Range("F10").Value
Application.Dialogs(xlDialogSaveAs).Show ("c:\" & savedir & "\" & fname)
End Sub

This works when I click run or run macro, but I need to activate it to run
when I select save or saveas button.

"dan dungan" wrote:

What error are you getting?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clicked NO to save, should have clicked YES Jenn Excel Discussion (Misc queries) 1 March 8th 10 09:04 PM
opened excel file from email & clicked save after modify . Where i bravorimes Excel Discussion (Misc queries) 2 July 27th 08 06:45 PM
Clicked on no to save too soon Tom Excel Discussion (Misc queries) 3 January 10th 08 06:42 PM
SAVE OR SAVE-AS with a file name derived from a cell on the spreadsheet... KLZA Excel Programming 0 July 31st 07 03:52 PM
Save File to Another Directory, but not change Users File Save location Mike Knight Excel Programming 1 May 28th 04 09:06 PM


All times are GMT +1. The time now is 12:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"