Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to rename a file in code 1

Status
Not open for further replies.

ToyFox

Programmer
Jan 24, 2009
161
US
I have a routine that takes a query, and calls Excel and opens a workbook file (template) then pastes the contents into the sheet, then emails the sheet as an attachment to a senior manager.
I want to copy that template to a MMDDYYFileName.XLS in the routine.
How can this be done in VBA.

Thx
 
Name oldpathname As newpathname

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
FileCopy SourceFile, DestinationFile

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I received a file not found error message
Here's My code...

Dim strFileName As String
Dim Mo
Dim Dy
Dim yr

strFileName = "G:\Tom\"

If Len(Day(Date)) = 1 Then
Dy = "0" & CStr(Day(Date))
Else
Dy = CStr(Day(Date))
End If

If Len(Month(Date)) = 1 Then
Mo = "0" & CStr(Month(Date))
Else
Mo = CStr(Month(Date))
End If

yr = Right(Year(Now), 2)

strFileName = strFileName & Mo & Dy & yr & "Daily_105_Activity_Report_Template.xls"

' copy file from Template to daily
FileCopy "Daily_105_Activity_Report_Template.xls", strFileName
 
Could it be that the file is open?
 
with just a quick visual inspection do you have a path for the source file?
Code:
FileCopy [red]"G:\Tom\" & [/red]"Daily_105_Activity_Report_Template.xls", strFileName

CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
Thank you. It was the path that I neglected to include.
 
ToyFox,
You have received some very good help in this thread. It is customary to recognize this with awarding a star. This also marks the thread in the forum as having at least one good answer.

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top