Opening file saved as current date

Y

Yepp12

I have the following code that I want to open a text file that is saved
as the current date. It works but opens the text file in a new excel
spreadsheet. Is there any way to open the file in my "tester.xls"
(which is where I have this macro)?


Code:
--------------------


Sub True()

Dim SourceBook As Workbook

ChDir ("C:\Program Files\helper")
Set SourceBook = Workbooks.Open(Filename:=Format(Date, "mm_dd_yy.txt"))

End Sub
 
T

Tom Ogilvy

Sub True()

Dim SourceBook As Workbook
Dim sh as Worksheet
With Activeworkbook
set sh = .Worksheets.Add(After:=.Worksheets(Worksheets.count))
End with
sh.Name = "Data1"
ChDir ("C:\Program Files\helper")
Set SourceBook = Workbooks.Open(Filename:=Format(Date, "mm_dd_yy.txt"))
SourceBook.Worksheets(1).UserRange.copy _
Destination:=sh.Range("A1")
sourceBook.Close SaveChanges:=False
End Sub
 
D

Dave Peterson

First, I wouldn't use True as a subroutine name. It looks too much like True
(as in the boolean value True.)

Sub myTrue()
Dim SourceBook As Workbook
Set SourceBook = Workbooks.Open _
(Filename:="C:\Program Files\helper\" & Format(Date, "mm_dd_yy.txt"))

activesheet.copy _
after:=thisworkbook.sheets(thisworkbook.sheets.count)

sourcebook.close savechanges:=false

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top