ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Where do I paste this Code? (https://www.excelbanter.com/excel-programming/280217-where-do-i-paste-code.html)

Kevin

Where do I paste this Code?
 
I was got this code from the web, but I'm not able to execute it. I did
pasted to a module and I cant get it to work, I even try pasting it on the
code of a control box button and will not work for me. Can some one please
tell me what moronic mistake I'm doing,
All I'm trying to do is save the time stamp from cell F3
thank you!
__________________________________________________ _______
Dim FilePth As String, FileNm As String
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Application.EnableEvents = False
If Range("F3").Value = "" Then
Application.EnableEvents = True
Exit Sub
End If
FilePth = "C:\TimeSheets\Test\"
FileNm = Range("F3").Value
ActiveWorkbook.SaveAs FilePth & FileNm, xlWorkbookNormal
Cancel = True
Application.EnableEvents = True

End Sub
__________________________________________________ ______
Kevin Brenner



Jase

Where do I paste this Code?
 
Um as far as I can see this should be doing the following

when you save the book, it makes copy in the
directory "C:\TimeSheets\Test\" and name it by whatever is
in cell "F3" (maybe you should put in an & ".xls" after
that line) then it does not save as the original name that
it is called. And since you are turning on enable events
at the end of all of this I assume that you turned off
enable events to start with somewhere (this line of code
is probably irrevialant) Other than that with no error
message I carn't tell you what is wrong

hope this helps
Jase
-----Original Message-----
I was got this code from the web, but I'm not able to

execute it. I did
pasted to a module and I cant get it to work, I even try

pasting it on the
code of a control box button and will not work for me.

Can some one please
tell me what moronic mistake I'm doing,
All I'm trying to do is save the time stamp from cell F3
thank you!
_________________________________________________ ________
Dim FilePth As String, FileNm As String
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As

Boolean, Cancel As
Boolean)
Application.EnableEvents = False
If Range("F3").Value = "" Then
Application.EnableEvents = True
Exit Sub
End If
FilePth = "C:\TimeSheets\Test\"
FileNm = Range("F3").Value
ActiveWorkbook.SaveAs FilePth & FileNm,

xlWorkbookNormal
Cancel = True
Application.EnableEvents = True

End Sub
_________________________________________________ _______
Kevin Brenner


.


Tom Ogilvy

Where do I paste this Code?
 
Go into the VB Editor and look in the project explorer. Find you workbook.
Under you workbook should be the ThisWorkbook entry. Right click on that
and select view code. Paste your code in that module. Remove it from other
locations. The below has been cleaned up to prevent problems with word wrap
in the email.

Dim FilePth As String, FileNm As String
Private Sub Workbook_BeforeSave(ByVal _
SaveAsUI As Boolean, Cancel As Boolean)
Application.EnableEvents = False
If Range("F3").Value = "" Then
Application.EnableEvents = True
Exit Sub
End If
FilePth = "C:\TimeSheets\Test\"
FileNm = Range("F3").Value
ActiveWorkbook.SaveAs FilePth & _
FileNm, xlWorkbookNormal
Cancel = True
Application.EnableEvents = True

End Sub
__________________________________________________ ______
Kevin Brenner

Kevin ! wrote in message
...
I was got this code from the web, but I'm not able to execute it. I did
pasted to a module and I cant get it to work, I even try pasting it on the
code of a control box button and will not work for me. Can some one please
tell me what moronic mistake I'm doing,
All I'm trying to do is save the time stamp from cell F3
thank you!
__________________________________________________ _______
Dim FilePth As String, FileNm As String
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Application.EnableEvents = False
If Range("F3").Value = "" Then
Application.EnableEvents = True
Exit Sub
End If
FilePth = "C:\TimeSheets\Test\"
FileNm = Range("F3").Value
ActiveWorkbook.SaveAs FilePth & FileNm, xlWorkbookNormal
Cancel = True
Application.EnableEvents = True

End Sub
__________________________________________________ ______
Kevin Brenner





Vasant Nanavati

Where do I paste this Code?
 
Hi Kevin:

Try pasting the code in the ThisWorkbook code module.

Regards,

Vasant.

"Kevin" ! wrote in message
...
I was got this code from the web, but I'm not able to execute it. I did
pasted to a module and I cant get it to work, I even try pasting it on the
code of a control box button and will not work for me. Can some one please
tell me what moronic mistake I'm doing,
All I'm trying to do is save the time stamp from cell F3
thank you!
__________________________________________________ _______
Dim FilePth As String, FileNm As String
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Application.EnableEvents = False
If Range("F3").Value = "" Then
Application.EnableEvents = True
Exit Sub
End If
FilePth = "C:\TimeSheets\Test\"
FileNm = Range("F3").Value
ActiveWorkbook.SaveAs FilePth & FileNm, xlWorkbookNormal
Cancel = True
Application.EnableEvents = True

End Sub
__________________________________________________ ______
Kevin Brenner





Kevin

Where do I paste this Code?
 
Thanks! everyone. I have been able to paste into MyWorkBook, the trouble is
I still can't see it as a macro when trying to run it.
What is the correct way to run this macro? I though it was a regular module
that would be executed when played on the macro tool box or executed from a
Forms Button.

Kevin


"Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message
...
Hi Kevin:

Try pasting the code in the ThisWorkbook code module.

Regards,

Vasant.

"Kevin" ! wrote in message
...
I was got this code from the web, but I'm not able to execute it. I did
pasted to a module and I cant get it to work, I even try pasting it on

the
code of a control box button and will not work for me. Can some one

please
tell me what moronic mistake I'm doing,
All I'm trying to do is save the time stamp from cell F3
thank you!
__________________________________________________ _______
Dim FilePth As String, FileNm As String
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Application.EnableEvents = False
If Range("F3").Value = "" Then
Application.EnableEvents = True
Exit Sub
End If
FilePth = "C:\TimeSheets\Test\"
FileNm = Range("F3").Value
ActiveWorkbook.SaveAs FilePth & FileNm, xlWorkbookNormal
Cancel = True
Application.EnableEvents = True

End Sub
__________________________________________________ ______
Kevin Brenner







Vasant Nanavati

Where do I paste this Code?
 
Hi Kevin:

This is an event macro. You don't run it; it runs itself right before the
Save event takes place.

If you want to be able to run it, put it back in a standard module but
rename it something else (not Workbook_BeforeSave) and remove the Private
keyword.

Regards,

Vasant.

"Kevin" ! wrote in message
...
Thanks! everyone. I have been able to paste into MyWorkBook, the trouble

is
I still can't see it as a macro when trying to run it.
What is the correct way to run this macro? I though it was a regular

module
that would be executed when played on the macro tool box or executed from

a
Forms Button.

Kevin


"Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message
...
Hi Kevin:

Try pasting the code in the ThisWorkbook code module.

Regards,

Vasant.

"Kevin" ! wrote in message
...
I was got this code from the web, but I'm not able to execute it. I

did
pasted to a module and I cant get it to work, I even try pasting it on

the
code of a control box button and will not work for me. Can some one

please
tell me what moronic mistake I'm doing,
All I'm trying to do is save the time stamp from cell F3
thank you!
__________________________________________________ _______
Dim FilePth As String, FileNm As String
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Application.EnableEvents = False
If Range("F3").Value = "" Then
Application.EnableEvents = True
Exit Sub
End If
FilePth = "C:\TimeSheets\Test\"
FileNm = Range("F3").Value
ActiveWorkbook.SaveAs FilePth & FileNm, xlWorkbookNormal
Cancel = True
Application.EnableEvents = True

End Sub
__________________________________________________ ______
Kevin Brenner










All times are GMT +1. The time now is 01:20 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com