Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Macro to log .xls file names

I have an existing macro that first allows the user to open an xls
file, then it copies data from the selected file into the one where
the macro is located. This info is added to the existing data that's
already there. The user will run the macro multiple times (once for
each file to be added) ....thus ending with a "master" file composed
of data from each file they had selected.

That part is done. Now, on a separate sheet in the macro file I'd
like to create a log where each row shows the name of each file that
had been opened and copied into the master, along with the date when
this was done.

How would such a macro work?

Thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Macro to log .xls file names

I'd create a log worksheet and give it a worksheet code name that won't
change (Say "Logsheet")

Let's assume when you open the worksheet, you do it something like this

Dim oWB as workbook
set oWB = workbooks.open(filename)

I'm also going to assume that you reference the active book (the book that
you are writing data to) as aWB (with the appropriate dimensions)

Dim oWB As Workbook
Dim aWB As Workbook
Dim WS As Worksheet
Dim myWS As Worksheet
Dim lRow As Long

Set aWB = ActiveWorkbook

For Each WS In aWB.Worksheets
If WS.CodeName = "Logsheet" Then
Set myWS = WS
Exit For
End If
Next WS

If Not myWS Is Nothing Then
lRow = myWS.Cells(myWS.Rows.Count, 1).End(xlUp).Row
If lRow < myWS.Rows.Count Then
myWS.Cells(lRow + 1, 1) = oWB.Name
myWS.Cells(lRow + 1, 2) = Date
End If
End If
--
HTH,
Barb Reinhardt



" wrote:

I have an existing macro that first allows the user to open an xls
file, then it copies data from the selected file into the one where
the macro is located. This info is added to the existing data that's
already there. The user will run the macro multiple times (once for
each file to be added) ....thus ending with a "master" file composed
of data from each file they had selected.

That part is done. Now, on a separate sheet in the macro file I'd
like to create a log where each row shows the name of each file that
had been opened and copied into the master, along with the date when
this was done.

How would such a macro work?

Thanks.


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
Macro recorded... tabs & file names changed, macro hangs Steve Excel Worksheet Functions 3 October 30th 09 11:41 AM
File Names within a Macro Function John Excel Worksheet Functions 2 December 5th 08 07:11 PM
Macro File Names John Excel Worksheet Functions 2 December 5th 08 06:27 AM
Macro File Names John Excel Worksheet Functions 1 December 5th 08 06:23 AM
Can a Macro use Different File Names? markmidwest Excel Programming 1 August 16th 06 10:04 PM


All times are GMT +1. The time now is 11:53 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"