+ Reply to Thread
Results 1 to 9 of 9

Username Log

  1. #1
    PaulJ
    Guest

    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. #2
    Bob Phillips
    Guest

    Re: 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" <PaulJ@discussions.microsoft.com> wrote in message
    news:63BCA8FD-4BCD-4590-B6C6-99DC2429A380@microsoft.com...
    > 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. #3
    PaulJ
    Guest

    Re: 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" <PaulJ@discussions.microsoft.com> wrote in message
    > news:63BCA8FD-4BCD-4590-B6C6-99DC2429A380@microsoft.com...
    > > 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. #4
    Bob Phillips
    Guest

    Re: Username Log

    So what is happening in your tests?

    --
    HTH

    Bob Phillips

    (remove nothere from email address if mailing direct)

    "PaulJ" <PaulJ@discussions.microsoft.com> wrote in message
    news:C803C4E7-5B68-4317-B3AB-15A89C7FD9A9@microsoft.com...
    > 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" <PaulJ@discussions.microsoft.com> wrote in message
    > > news:63BCA8FD-4BCD-4590-B6C6-99DC2429A380@microsoft.com...
    > > > 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. #5
    PaulJ
    Guest

    Re: 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" <PaulJ@discussions.microsoft.com> wrote in message
    > news:C803C4E7-5B68-4317-B3AB-15A89C7FD9A9@microsoft.com...
    > > 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" <PaulJ@discussions.microsoft.com> wrote in message
    > > > news:63BCA8FD-4BCD-4590-B6C6-99DC2429A380@microsoft.com...
    > > > > 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. #6
    Bob Phillips
    Guest

    Re: 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" <PaulJ@discussions.microsoft.com> wrote in message
    news:EDC16B21-423F-4CE1-B52E-C1917C3C45C8@microsoft.com...
    > 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" <PaulJ@discussions.microsoft.com> wrote in message
    > > news:C803C4E7-5B68-4317-B3AB-15A89C7FD9A9@microsoft.com...
    > > > 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" <PaulJ@discussions.microsoft.com> wrote in message
    > > > > news:63BCA8FD-4BCD-4590-B6C6-99DC2429A380@microsoft.com...
    > > > > > 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. #7
    PaulJ
    Guest

    Re: 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" <PaulJ@discussions.microsoft.com> wrote in message
    > news:EDC16B21-423F-4CE1-B52E-C1917C3C45C8@microsoft.com...
    > > 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" <PaulJ@discussions.microsoft.com> wrote in message
    > > > news:C803C4E7-5B68-4317-B3AB-15A89C7FD9A9@microsoft.com...
    > > > > 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" <PaulJ@discussions.microsoft.com> wrote in message
    > > > > > news:63BCA8FD-4BCD-4590-B6C6-99DC2429A380@microsoft.com...
    > > > > > > 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. #8
    Bob Phillips
    Guest

    Re: 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" <bob.phillips@notheretiscali.co.uk> wrote in message
    news:%23OydACSPGHA.2828@TK2MSFTNGP12.phx.gbl...
    > 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" <PaulJ@discussions.microsoft.com> wrote in message
    > news:EDC16B21-423F-4CE1-B52E-C1917C3C45C8@microsoft.com...
    > > 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" <PaulJ@discussions.microsoft.com> wrote in message
    > > > news:C803C4E7-5B68-4317-B3AB-15A89C7FD9A9@microsoft.com...
    > > > > 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" <PaulJ@discussions.microsoft.com> wrote in message
    > > > > > news:63BCA8FD-4BCD-4590-B6C6-99DC2429A380@microsoft.com...
    > > > > > > 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. #9
    PaulJ
    Guest

    Re: 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" <bob.phillips@notheretiscali.co.uk> wrote in message
    > news:%23OydACSPGHA.2828@TK2MSFTNGP12.phx.gbl...
    > > 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" <PaulJ@discussions.microsoft.com> wrote in message
    > > news:EDC16B21-423F-4CE1-B52E-C1917C3C45C8@microsoft.com...
    > > > 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" <PaulJ@discussions.microsoft.com> wrote in message
    > > > > news:C803C4E7-5B68-4317-B3AB-15A89C7FD9A9@microsoft.com...
    > > > > > 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" <PaulJ@discussions.microsoft.com> wrote in message
    > > > > > > news:63BCA8FD-4BCD-4590-B6C6-99DC2429A380@microsoft.com...
    > > > > > > > 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1