473,669 Members | 2,409 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding Date to File name

62 New Member
Hi, I have written a VBA program that runs on Excel and puts data on the excel sheet. This runs everyday. I want to be adding the dates to the files, this date is gotten from the excel sheet that uploads into the report excel file. Below is the Code I wrote which doesnt work, please could you help me

Expand|Select|Wrap|Line Numbers
  1.     Sheets("Matrix sheet").Select
  2.     Today = Cells(1, 1)       'The location of the date on the raw sheet
  3.     Today = Format(Today, "dd-mm-yyyy")
  4.     Windows("cells.xls").Close savechanges:=True, Filename:="c:\Daily_Alerts\Daily Alerts_ " & Today & " "
  5.  
Jul 4 '07 #1
5 4647
Killer42
8,435 Recognized Expert Expert
Apart from the slightly questionable habit of using the same variable (Today) to hold data of two different formats (date and string) what seems to be the problem? I thought the code looked alright.

Hint: the problem is not "it doesn't work". You need to be specific. For example, have you stopped the code at the point of executing the Close and examined the string that is being supplied as the filename? What is the string? Is an error occuring? If so, what are the error details?
Jul 5 '07 #2
nkechifesie
62 New Member
I have resolved it. The issue was that .xls was not included in the file name. Thanks for all your help.
Below is the code that works now

Expand|Select|Wrap|Line Numbers
  1. Dim Today As Date
  2. Dim Todayb As String
  3. Today = Cells(1, 1)
  4. Todayb = Format(Today, "dd-mm-yyyy")
  5. Todayb = Todayb & ".xls"
  6. Windows("cells.xls").Close savechanges:=True, Filename:="c:\Daily_Alerts\Daily Alerts_" & Todayb & " "
  7.  
Jul 6 '07 #3
Killer42
8,435 Recognized Expert Expert
Ok, glad to see you got it sorted out. Debugging usually ends up being about checking every little detail like that.
Jul 8 '07 #4
chiz
1 New Member
I am attempting to add a date to a file name. I want the first file to end with
30-june-07, and each file going forward to end with the end of the month. I keep receiving the 'Invalid procedure call ir argument' error. Here is my code:

Expand|Select|Wrap|Line Numbers
  1. Sheets("Portfolio").Select
  2.     Sheets("Portfolio").Copy
  3.     ChDir "P:\Conduits\Servicing\Port Stats\Allied\Archive\Portfolio"
  4.     ActiveWorkbook.SaveAs Filename:= _
  5.         "P:\Conduits\Servicing\Port Stats\Allied\Archive\Portfolio\Portfolio_" & DateAdd(m, 1, 30 - Jun - 7) & " ", FileFormat:= _
  6.         xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False
  7.     ActiveWindow.Close
  8.     Sheets("WA").Select
  9.     Sheets("WA").Copy
  10.     ChDir "P:\Conduits\Servicing\Port Stats\Allied\Archive\WA"
  11.     ActiveWorkbook.SaveAs Filename:= _
  12.         "P:\Conduits\Servicing\Port Stats\Allied\Archive\WA\WA_" & DateAdd(m, 1, 30 - Jun - 7) & " ", FileFormat:= _
  13.         xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
  14.         , CreateBackup:=False
  15.     ActiveWindow.Close
  16. End Sub
Thanks for your help!
Aug 10 '07 #5
Killer42
8,435 Recognized Expert Expert
You didn't say which line produced the error. However, I think this function call...
DateAdd(m, 1, 30 - Jun - 7)
probably has some problems. You are telling it to take 30, subtract some variable called Jun, then subtract 7, and treat the result as a date value. Somehow, I don't think this is what you intended.

You might (I haven't checked) get away with writing it this way, if you put # delimiters around your literal value. For example...
DateAdd(m, 1, #30-Jun-07#)

Another thing to consider is this. The DateAdd function will return a date value. You are then placing it in a string, which forces VB to convert it to a string. If you want it to be presented in a particular format (eg DD-MMM-YY) then you might need to use something like the Format() function to force it. However, you may be perfectly happy with your computer's default format, in which case don't worry about it. But, if you need to be certain the format won't change when run on someone else's system, you had best enforce your format.
Aug 11 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
3068
by: 6thirty | last post by:
Hi, I've created a stocktaking database using Access XP. This is indexed by two fields - part number and shelf location. I am currently inputting all the data via a form. When I have entered a record such as: part number 202354-001 location C1-01
3
2339
by: Ankit Aneja | last post by:
I have a strange situation and I have no idea how to solve this. Its a Recruitment Search Page,in the Admin Page, for every button click event the Admin Person has to create a checkbox on the users page. So whenever the Admin person comes to know about the new category in the market he will be adding as different Sub-Categories for example ABAP, BDC etc..etc.. on every click event as Checkboxes. And these controls(checkboxes) should remain...
2
21073
by: markryde | last post by:
Hello, I am trying to add the current date to a file name in python script like thus: import os import sys import rpm import time import datetime
3
2005
by: xxtokenxx | last post by:
I am writing a birthday list for a site for my school. While developing it. Currently the code for the output of birthdays is: <html><head> <title>Birthday List</title><script type="text/javascript"> var arrBday = , , , , , ,
1
4137
by: aRTx | last post by:
<? /* Directory Listing Script - Version 2 ==================================== Script Author: Artani <artan_p@msn.com>. www.artxcenter.com REQUIREMENTS ============ This script requires PHP and GD2 if you wish to use the
8
35972
by: David | last post by:
I'm trying to add a date and time to an html form, but I'm having a bit of trouble getting it working. Any suggestions? Thanks! ~ David (merlin001_at_gmail_dot_com)
4
3955
tolkienarda
by: tolkienarda | last post by:
hi all I am working on a php driven database program for a literacy program, it will allow them to keep track of classes and students, the part i am strugling with is adding new classes, the add_class page looks like: <body> ADD CLASS<br> Class Title: <input type="text" value="class_title"><br> Class Name: <input type="text" value="class_name">(Must be Unique)<br> <input type="checkbox" name="children" value="children">Children's...
2
7657
by: Ken Fine | last post by:
I want to add the security question and answer security feature to the ChangePassword control. I am aware that this functionality is built into the PasswordRecovery tool. I have implemented the PasswordRecovery with a Password reset required; a temporary password is sent to the account on file. I want an extra layer of security to accommodate the very unlikely contingency that someone's e-mail account is compromised. Challenging with the...
1
4895
by: swethak | last post by:
Hi, I am desiging the calendar application for that purpose i used the below code. But it is for only displys calendar. And also i want to add the events to calendar. In that code displys the events when click on that date that perticular event displyed in a text box.But my requirement is to when click on that date that related event displyed in same td row not the text box. and also i add the events to that calendar.plz advice how to...
0
8465
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8658
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7407
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6210
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4384
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2792
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2029
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.