#1   Report Post  
Posted to microsoft.public.excel.misc
PaulJ
 
Posts: n/a
Default Username Log

Hi,
I'm using the following macro in the ThisWorkbook module which creates a log
when somebody opens a file:

Private Sub Workbook_Open()
Open ThisWorkbook.Path & "\usage.log" For Append As #1
Print #1, Environ("username"), Now, ThisWorkbook.FullName
Close #1
End Sub

It works perfectly, but I only have it in a template. My question
therefore, is can the macro be adapted so that if someone opens the template,
does File - Save As and renames it, this new file is also listed on the log
without having to re-open it?

Hope this makes sense!
  #2   Report Post  
Posted to microsoft.public.excel.misc
Bob Phillips
 
Posts: n/a
Default Username Log

Try this

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim sFilename As String
If SaveAsUI Then
Cancel = True
sFilename = Application.GetSaveAsFilename( _
fileFilter:="Microsoft Excel Files (*.xls), *.xls")
If sFilename < "False" Then
ThisWorkbook.SaveAs sFilename
Open ThisWorkbook.Path & "\usage.log" For Append As #1
Print #1, Environ("username"), Now, ThisWorkbook.FullName
Close #1
End If
End If
End Sub

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"PaulJ" wrote in message
...
Hi,
I'm using the following macro in the ThisWorkbook module which creates a

log
when somebody opens a file:

Private Sub Workbook_Open()
Open ThisWorkbook.Path & "\usage.log" For Append As #1
Print #1, Environ("username"), Now, ThisWorkbook.FullName
Close #1
End Sub

It works perfectly, but I only have it in a template. My question
therefore, is can the macro be adapted so that if someone opens the

template,
does File - Save As and renames it, this new file is also listed on the

log
without having to re-open it?

Hope this makes sense!



  #3   Report Post  
Posted to microsoft.public.excel.misc
PaulJ
 
Posts: n/a
Default Username Log

Thanks Bob, but it's not working as I would like just yet. I don't know much
VBA so the syntax below doesn't mean a great deal to me, but maybe I should
explain further...

If the code was in a file named Template, then on opening this file a log is
created containing my username, time and filename. If I then saved this
Template as Template2 I require the details of this file to also appear on
the same log as soon as it is created.

Thanks :-)
"Bob Phillips" wrote:

Try this

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim sFilename As String
If SaveAsUI Then
Cancel = True
sFilename = Application.GetSaveAsFilename( _
fileFilter:="Microsoft Excel Files (*.xls), *.xls")
If sFilename < "False" Then
ThisWorkbook.SaveAs sFilename
Open ThisWorkbook.Path & "\usage.log" For Append As #1
Print #1, Environ("username"), Now, ThisWorkbook.FullName
Close #1
End If
End If
End Sub

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"PaulJ" wrote in message
...
Hi,
I'm using the following macro in the ThisWorkbook module which creates a

log
when somebody opens a file:

Private Sub Workbook_Open()
Open ThisWorkbook.Path & "\usage.log" For Append As #1
Print #1, Environ("username"), Now, ThisWorkbook.FullName
Close #1
End Sub

It works perfectly, but I only have it in a template. My question
therefore, is can the macro be adapted so that if someone opens the

template,
does File - Save As and renames it, this new file is also listed on the

log
without having to re-open it?

Hope this makes sense!




  #4   Report Post  
Posted to microsoft.public.excel.misc
Bob Phillips
 
Posts: n/a
Default Username Log

So what is happening in your tests?

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"PaulJ" wrote in message
...
Thanks Bob, but it's not working as I would like just yet. I don't know

much
VBA so the syntax below doesn't mean a great deal to me, but maybe I

should
explain further...

If the code was in a file named Template, then on opening this file a log

is
created containing my username, time and filename. If I then saved this
Template as Template2 I require the details of this file to also appear on
the same log as soon as it is created.

Thanks :-)
"Bob Phillips" wrote:

Try this

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim sFilename As String
If SaveAsUI Then
Cancel = True
sFilename = Application.GetSaveAsFilename( _
fileFilter:="Microsoft Excel Files (*.xls), *.xls")
If sFilename < "False" Then
ThisWorkbook.SaveAs sFilename
Open ThisWorkbook.Path & "\usage.log" For Append As #1
Print #1, Environ("username"), Now, ThisWorkbook.FullName
Close #1
End If
End If
End Sub

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"PaulJ" wrote in message
...
Hi,
I'm using the following macro in the ThisWorkbook module which creates

a
log
when somebody opens a file:

Private Sub Workbook_Open()
Open ThisWorkbook.Path & "\usage.log" For Append As #1
Print #1, Environ("username"), Now, ThisWorkbook.FullName
Close #1
End Sub

It works perfectly, but I only have it in a template. My question
therefore, is can the macro be adapted so that if someone opens the

template,
does File - Save As and renames it, this new file is also listed on

the
log
without having to re-open it?

Hope this makes sense!






  #5   Report Post  
Posted to microsoft.public.excel.misc
PaulJ
 
Posts: n/a
Default Username Log

Nothing is going into the log at all right now. Maybe the problem is the
Private Sub title, which is showing up in red text? When I open the file I'm
not getting the macro security warning, so I guess the macro is not being
recognised?

"Bob Phillips" wrote:

So what is happening in your tests?

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"PaulJ" wrote in message
...
Thanks Bob, but it's not working as I would like just yet. I don't know

much
VBA so the syntax below doesn't mean a great deal to me, but maybe I

should
explain further...

If the code was in a file named Template, then on opening this file a log

is
created containing my username, time and filename. If I then saved this
Template as Template2 I require the details of this file to also appear on
the same log as soon as it is created.

Thanks :-)
"Bob Phillips" wrote:

Try this

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim sFilename As String
If SaveAsUI Then
Cancel = True
sFilename = Application.GetSaveAsFilename( _
fileFilter:="Microsoft Excel Files (*.xls), *.xls")
If sFilename < "False" Then
ThisWorkbook.SaveAs sFilename
Open ThisWorkbook.Path & "\usage.log" For Append As #1
Print #1, Environ("username"), Now, ThisWorkbook.FullName
Close #1
End If
End If
End Sub

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"PaulJ" wrote in message
...
Hi,
I'm using the following macro in the ThisWorkbook module which creates

a
log
when somebody opens a file:

Private Sub Workbook_Open()
Open ThisWorkbook.Path & "\usage.log" For Append As #1
Print #1, Environ("username"), Now, ThisWorkbook.FullName
Close #1
End Sub

It works perfectly, but I only have it in a template. My question
therefore, is can the macro be adapted so that if someone opens the
template,
does File - Save As and renames it, this new file is also listed on

the
log
without having to re-open it?

Hope this makes sense!








  #6   Report Post  
Posted to microsoft.public.excel.misc
Bob Phillips
 
Posts: n/a
Default Username Log

Paul,

I think it is just NG wrap-around problems. It certainly works, I tested it
(after you replied <vbg).

Try this update

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
Dim sFilename As String
If SaveAsUI Then
Cancel = True
sFilename = Application.GetSaveAsFilename( _
fileFilter:="Microsoft Excel Files (*.xls), *.xls")
If sFilename < "False" Then
ThisWorkbook.SaveAs sFilename
Open ThisWorkbook.Path & "\usage.log" For Append As #1
Print #1, Environ("username"), Now, ThisWorkbook.FullName
Close #1
End If
End If
End Sub

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"PaulJ" wrote in message
...
Nothing is going into the log at all right now. Maybe the problem is the
Private Sub title, which is showing up in red text? When I open the file

I'm
not getting the macro security warning, so I guess the macro is not being
recognised?

"Bob Phillips" wrote:

So what is happening in your tests?

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"PaulJ" wrote in message
...
Thanks Bob, but it's not working as I would like just yet. I don't

know
much
VBA so the syntax below doesn't mean a great deal to me, but maybe I

should
explain further...

If the code was in a file named Template, then on opening this file a

log
is
created containing my username, time and filename. If I then saved

this
Template as Template2 I require the details of this file to also

appear on
the same log as soon as it is created.

Thanks :-)
"Bob Phillips" wrote:

Try this

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim sFilename As String
If SaveAsUI Then
Cancel = True
sFilename = Application.GetSaveAsFilename( _
fileFilter:="Microsoft Excel Files (*.xls), *.xls")
If sFilename < "False" Then
ThisWorkbook.SaveAs sFilename
Open ThisWorkbook.Path & "\usage.log" For Append As #1
Print #1, Environ("username"), Now,

ThisWorkbook.FullName
Close #1
End If
End If
End Sub

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"PaulJ" wrote in message
...
Hi,
I'm using the following macro in the ThisWorkbook module which

creates
a
log
when somebody opens a file:

Private Sub Workbook_Open()
Open ThisWorkbook.Path & "\usage.log" For Append As #1
Print #1, Environ("username"), Now, ThisWorkbook.FullName
Close #1
End Sub

It works perfectly, but I only have it in a template. My question
therefore, is can the macro be adapted so that if someone opens

the
template,
does File - Save As and renames it, this new file is also listed

on
the
log
without having to re-open it?

Hope this makes sense!








  #7   Report Post  
Posted to microsoft.public.excel.misc
PaulJ
 
Posts: n/a
Default Username Log

Thanks Bob that certainly seems to have done the trick. Just one final thing
though! The saved file is appearing in the log but not the original
template...is there a way to have both?

Thanks for your patience!
Paul

"Bob Phillips" wrote:

Paul,

I think it is just NG wrap-around problems. It certainly works, I tested it
(after you replied <vbg).

Try this update

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
Dim sFilename As String
If SaveAsUI Then
Cancel = True
sFilename = Application.GetSaveAsFilename( _
fileFilter:="Microsoft Excel Files (*.xls), *.xls")
If sFilename < "False" Then
ThisWorkbook.SaveAs sFilename
Open ThisWorkbook.Path & "\usage.log" For Append As #1
Print #1, Environ("username"), Now, ThisWorkbook.FullName
Close #1
End If
End If
End Sub

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"PaulJ" wrote in message
...
Nothing is going into the log at all right now. Maybe the problem is the
Private Sub title, which is showing up in red text? When I open the file

I'm
not getting the macro security warning, so I guess the macro is not being
recognised?

"Bob Phillips" wrote:

So what is happening in your tests?

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"PaulJ" wrote in message
...
Thanks Bob, but it's not working as I would like just yet. I don't

know
much
VBA so the syntax below doesn't mean a great deal to me, but maybe I
should
explain further...

If the code was in a file named Template, then on opening this file a

log
is
created containing my username, time and filename. If I then saved

this
Template as Template2 I require the details of this file to also

appear on
the same log as soon as it is created.

Thanks :-)
"Bob Phillips" wrote:

Try this

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim sFilename As String
If SaveAsUI Then
Cancel = True
sFilename = Application.GetSaveAsFilename( _
fileFilter:="Microsoft Excel Files (*.xls), *.xls")
If sFilename < "False" Then
ThisWorkbook.SaveAs sFilename
Open ThisWorkbook.Path & "\usage.log" For Append As #1
Print #1, Environ("username"), Now,

ThisWorkbook.FullName
Close #1
End If
End If
End Sub

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"PaulJ" wrote in message
...
Hi,
I'm using the following macro in the ThisWorkbook module which

creates
a
log
when somebody opens a file:

Private Sub Workbook_Open()
Open ThisWorkbook.Path & "\usage.log" For Append As #1
Print #1, Environ("username"), Now, ThisWorkbook.FullName
Close #1
End Sub

It works perfectly, but I only have it in a template. My question
therefore, is can the macro be adapted so that if someone opens

the
template,
does File - Save As and renames it, this new file is also listed

on
the
log
without having to re-open it?

Hope this makes sense!









  #8   Report Post  
Posted to microsoft.public.excel.misc
Bob Phillips
 
Posts: n/a
Default Username Log

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
Dim sFilename As String
If SaveAsUI Then
Cancel = True
sFilename = Application.GetSaveAsFilename( _
fileFilter:="Microsoft Excel Files (*.xls), *.xls")
If sFilename < "False" Then
Open ThisWorkbook.Path & "\usage.log" For Append As #1
Print #1, Environ("username"), Now, ThisWorkbook.FullName
ThisWorkbook.SaveAs sFilename
Print #1, Environ("username"), Now, ThisWorkbook.FullName
Close #1
End If
End If
End Sub

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Bob Phillips" wrote in message
...
Paul,

I think it is just NG wrap-around problems. It certainly works, I tested

it
(after you replied <vbg).

Try this update

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
Dim sFilename As String
If SaveAsUI Then
Cancel = True
sFilename = Application.GetSaveAsFilename( _
fileFilter:="Microsoft Excel Files (*.xls), *.xls")
If sFilename < "False" Then
ThisWorkbook.SaveAs sFilename
Open ThisWorkbook.Path & "\usage.log" For Append As #1
Print #1, Environ("username"), Now, ThisWorkbook.FullName
Close #1
End If
End If
End Sub

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"PaulJ" wrote in message
...
Nothing is going into the log at all right now. Maybe the problem is

the
Private Sub title, which is showing up in red text? When I open the

file
I'm
not getting the macro security warning, so I guess the macro is not

being
recognised?

"Bob Phillips" wrote:

So what is happening in your tests?

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"PaulJ" wrote in message
...
Thanks Bob, but it's not working as I would like just yet. I don't

know
much
VBA so the syntax below doesn't mean a great deal to me, but maybe I
should
explain further...

If the code was in a file named Template, then on opening this file

a
log
is
created containing my username, time and filename. If I then saved

this
Template as Template2 I require the details of this file to also

appear on
the same log as soon as it is created.

Thanks :-)
"Bob Phillips" wrote:

Try this

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel

As
Boolean)
Dim sFilename As String
If SaveAsUI Then
Cancel = True
sFilename = Application.GetSaveAsFilename( _
fileFilter:="Microsoft Excel Files (*.xls), *.xls")
If sFilename < "False" Then
ThisWorkbook.SaveAs sFilename
Open ThisWorkbook.Path & "\usage.log" For Append As #1
Print #1, Environ("username"), Now,

ThisWorkbook.FullName
Close #1
End If
End If
End Sub

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"PaulJ" wrote in message
...
Hi,
I'm using the following macro in the ThisWorkbook module which

creates
a
log
when somebody opens a file:

Private Sub Workbook_Open()
Open ThisWorkbook.Path & "\usage.log" For Append As #1
Print #1, Environ("username"), Now, ThisWorkbook.FullName
Close #1
End Sub

It works perfectly, but I only have it in a template. My

question
therefore, is can the macro be adapted so that if someone opens

the
template,
does File - Save As and renames it, this new file is also listed

on
the
log
without having to re-open it?

Hope this makes sense!










  #9   Report Post  
Posted to microsoft.public.excel.misc
PaulJ
 
Posts: n/a
Default Username Log

Fantastic! Thanks very much Bob :)

"Bob Phillips" wrote:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
Dim sFilename As String
If SaveAsUI Then
Cancel = True
sFilename = Application.GetSaveAsFilename( _
fileFilter:="Microsoft Excel Files (*.xls), *.xls")
If sFilename < "False" Then
Open ThisWorkbook.Path & "\usage.log" For Append As #1
Print #1, Environ("username"), Now, ThisWorkbook.FullName
ThisWorkbook.SaveAs sFilename
Print #1, Environ("username"), Now, ThisWorkbook.FullName
Close #1
End If
End If
End Sub

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Bob Phillips" wrote in message
...
Paul,

I think it is just NG wrap-around problems. It certainly works, I tested

it
(after you replied <vbg).

Try this update

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
Dim sFilename As String
If SaveAsUI Then
Cancel = True
sFilename = Application.GetSaveAsFilename( _
fileFilter:="Microsoft Excel Files (*.xls), *.xls")
If sFilename < "False" Then
ThisWorkbook.SaveAs sFilename
Open ThisWorkbook.Path & "\usage.log" For Append As #1
Print #1, Environ("username"), Now, ThisWorkbook.FullName
Close #1
End If
End If
End Sub

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"PaulJ" wrote in message
...
Nothing is going into the log at all right now. Maybe the problem is

the
Private Sub title, which is showing up in red text? When I open the

file
I'm
not getting the macro security warning, so I guess the macro is not

being
recognised?

"Bob Phillips" wrote:

So what is happening in your tests?

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"PaulJ" wrote in message
...
Thanks Bob, but it's not working as I would like just yet. I don't

know
much
VBA so the syntax below doesn't mean a great deal to me, but maybe I
should
explain further...

If the code was in a file named Template, then on opening this file

a
log
is
created containing my username, time and filename. If I then saved

this
Template as Template2 I require the details of this file to also

appear on
the same log as soon as it is created.

Thanks :-)
"Bob Phillips" wrote:

Try this

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel

As
Boolean)
Dim sFilename As String
If SaveAsUI Then
Cancel = True
sFilename = Application.GetSaveAsFilename( _
fileFilter:="Microsoft Excel Files (*.xls), *.xls")
If sFilename < "False" Then
ThisWorkbook.SaveAs sFilename
Open ThisWorkbook.Path & "\usage.log" For Append As #1
Print #1, Environ("username"), Now,

ThisWorkbook.FullName
Close #1
End If
End If
End Sub

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"PaulJ" wrote in message
...
Hi,
I'm using the following macro in the ThisWorkbook module which

creates
a
log
when somebody opens a file:

Private Sub Workbook_Open()
Open ThisWorkbook.Path & "\usage.log" For Append As #1
Print #1, Environ("username"), Now, ThisWorkbook.FullName
Close #1
End Sub

It works perfectly, but I only have it in a template. My

question
therefore, is can the macro be adapted so that if someone opens

the
template,
does File - Save As and renames it, this new file is also listed

on
the
log
without having to re-open it?

Hope this makes sense!











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
Including Environ Username in Cell swieduwi Excel Worksheet Functions 9 March 30th 06 04:43 PM
How to change initial username? EeVee Excel Discussion (Misc queries) 1 January 3rd 06 02:22 AM
NT Username ceemo Excel Discussion (Misc queries) 4 August 2nd 05 04:39 PM
How do I populate a cell with the NT Logon username? Mike Excel Discussion (Misc queries) 1 June 3rd 05 07:58 AM
How can I print the username or computername from excel? YesNo Excel Discussion (Misc queries) 0 March 9th 05 06:03 PM


All times are GMT +1. The time now is 05:31 PM.

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

About Us

"It's about Microsoft Excel"