Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Add Time in Filename


I have a VBA that has an statement:
Filename = "" & WO & "_" & Tract & "_" & Supplier & "_" & Dates & "_" & Time
& ""
I want to type the time in the excel cell =now() instead of typing:
Dates = 20050923 (September 23, 2005)
Time = 1145 ( 11:45AM)

Every time I type in the cell =Now() I have an error message that says the
file cannot be found
Does anybody knows how to do it?

Thanks.
Maperalia

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 145
Default Add Time in Filename

Every time you type in the cell =Now()
you get date+time
so & Time is never solely 1145

"maperalia" wrote in message
...

I have a VBA that has an statement:
Filename = "" & WO & "_" & Tract & "_" & Supplier & "_" & Dates & "_" &

Time
& ""
I want to type the time in the excel cell "=now()" instead of typing:
Dates = 20050923 (September 23, 2005)
Time = 1145 ( 11:45AM)

Every time I type in the cell =Now() I have an error message that says

"the
file cannot be found"
Does anybody knows how to do it?

Thanks.
Maperalia



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Add Time in Filename

I think the problem may lie in the underlying value of the date or
time. Dates and times are stored as Longs. So when you think you're
retrieving the "1145 AM" value from the cell, you're actually
retrieving a date serial number. Try changing it as follows:

- For the Dates cell, set the formula to:
=TEXT(TODAY(),"yyyymmdd").

- For the Time cell, set the formula to:
=TEXT(TIME(HOUR(NOW()),MINUTE(NOW()),SECOND(NOW()) ),"hhmm AM/PM")

Then in the VBA code get the
Dates = ActiveSheet.Range("A1").Text 'change to actual cell
Time = ActiveSheet.Range("B1").Text 'change to actual cell

The =TEXT() formula isn't absolutely necessary. If you grab the
Range.Value property, you'll likely get some serial number for the date
and time. But if you use Range.Text, you'll get the text as displayed.

Using the =TEXT() formula in the cells is just an added insurance
policy. It let's you use the Range.Value or Range.Text and still get
the correct result.


HTH,

Nick Hebb
BreezeTree Software
http://www.breezetree.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Add Time in Filename

I think the problem may lie in the underlying value of the date or
time. Dates and times are stored as Longs. So when you think you're
retrieving the "1145 AM" value from the cell, you're actually
retrieving a date serial number. Try changing it as follows:

- For the Dates cell, set the formula to:
=TEXT(TODAY(),"yyyymmdd").

- For the Time cell, set the formula to:
=TEXT(TIME(HOUR(NOW()),MINUTE(NOW()),SECOND(NOW()) ),"hhmm AM/PM")

Then in the VBA code get the
Dates = ActiveSheet.Range("A1").Text 'change to actual cell
Time = ActiveSheet.Range("B1").Text 'change to actual cell

The =TEXT() formula isn't absolutely necessary. If you grab the
Range.Value property, you'll likely get some serial number for the date
and time. But if you use Range.Text, you'll get the text as displayed.

Using the =TEXT() formula in the cells is just an added insurance
policy. It let's you use the Range.Value or Range.Text and still get
the correct result.


HTH,

Nick Hebb
BreezeTree Software
http://www.breezetree.com

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Add Time in Filename

So Dates and Time are variables that refer back to cells on a worksheet.

(I think I'd stay away from Time as a variable name.)

dim myDate as string
dim myTime as string
dim myDateTime as string

mydate = format(worksheets("sheet1").range("a1").value,"yyy ymmdd")
mytime = format(worksheets("sheet1").range("a2").value,"hhm m")

or if you have =now() in that cell:
mydatetime = format(worksheets("sheet1").range("a3").value,"yyy ymmdd_hhmm")

Then you could use:

Filename _
= "" & WO & "_" & Tract & "_" & Supplier & "_" & myDate & "_" & myTime

or
Filename = "" & WO & "_" & Tract & "_" & Supplier & "_" & mydatetime

=====
You've got to remove those slashes from the date and colons from the time.


maperalia wrote:

I have a VBA that has an statement:
Filename = "" & WO & "_" & Tract & "_" & Supplier & "_" & Dates & "_" & Time
& ""
I want to type the time in the excel cell =now() instead of typing:
Dates = 20050923 (September 23, 2005)
Time = 1145 ( 11:45AM)

Every time I type in the cell =Now() I have an error message that says the
file cannot be found
Does anybody knows how to do it?

Thanks.
Maperalia


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Add Time in Filename

Dave;
Thanks for your response. I put the information but I got the following
error message:

Run-time error '6'
over flow

Then is hightligthing in the statement:

Filename = "" & WO & "_" & Tract & "_" & Supplier & "_" & mydatetime

Could you please tell me how to fix it please?

Regards.
Maperalia

"Dave Peterson" wrote:

So Dates and Time are variables that refer back to cells on a worksheet.

(I think I'd stay away from Time as a variable name.)

dim myDate as string
dim myTime as string
dim myDateTime as string

mydate = format(worksheets("sheet1").range("a1").value,"yyy ymmdd")
mytime = format(worksheets("sheet1").range("a2").value,"hhm m")

or if you have =now() in that cell:
mydatetime = format(worksheets("sheet1").range("a3").value,"yyy ymmdd_hhmm")

Then you could use:

Filename _
= "" & WO & "_" & Tract & "_" & Supplier & "_" & myDate & "_" & myTime

or
Filename = "" & WO & "_" & Tract & "_" & Supplier & "_" & mydatetime

=====
You've got to remove those slashes from the date and colons from the time.


maperalia wrote:

I have a VBA that has an statement:
Filename = "" & WO & "_" & Tract & "_" & Supplier & "_" & Dates & "_" & Time
& ""
I want to type the time in the excel cell âœ=now()❠instead of typing:
Dates = 20050923 (September 23, 2005)
Time = 1145 ( 11:45AM)

Every time I type in the cell =Now() I have an error message that says âœthe
file cannot be foundâ
Does anybody knows how to do it?

Thanks.
Maperalia


--

Dave Peterson

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Add Time in Filename

One of those variables isn't large enough to hold what you're trying to put into
it.

It might be as simple as changing:

dim WO as Integer
to
dim WO as Long

(but that's just a guess--without seeing the code and knowing the data, it's
difficult to say.)

maperalia wrote:

Dave;
Thanks for your response. I put the information but I got the following
error message:

Run-time error '6'
over flow

Then is hightligthing in the statement:

Filename = "" & WO & "_" & Tract & "_" & Supplier & "_" & mydatetime

Could you please tell me how to fix it please?

Regards.
Maperalia

"Dave Peterson" wrote:

So Dates and Time are variables that refer back to cells on a worksheet.

(I think I'd stay away from Time as a variable name.)

dim myDate as string
dim myTime as string
dim myDateTime as string

mydate = format(worksheets("sheet1").range("a1").value,"yyy ymmdd")
mytime = format(worksheets("sheet1").range("a2").value,"hhm m")

or if you have =now() in that cell:
mydatetime = format(worksheets("sheet1").range("a3").value,"yyy ymmdd_hhmm")

Then you could use:

Filename _
= "" & WO & "_" & Tract & "_" & Supplier & "_" & myDate & "_" & myTime

or
Filename = "" & WO & "_" & Tract & "_" & Supplier & "_" & mydatetime

=====
You've got to remove those slashes from the date and colons from the time.


maperalia wrote:

I have a VBA that has an statement:
Filename = "" & WO & "_" & Tract & "_" & Supplier & "_" & Dates & "_" & Time
& ""
I want to type the time in the excel cell âœ=now()❠instead of typing:
Dates = 20050923 (September 23, 2005)
Time = 1145 ( 11:45AM)

Every time I type in the cell =Now() I have an error message that says âœthe
file cannot be foundâ
Does anybody knows how to do it?

Thanks.
Maperalia


--

Dave Peterson


--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Add Time in Filename

Dave;
Thank you very much for your advise. The program is working
WONDERFUL!!!!!!!!!.

I really appreciate your helping me in this matter.

Best regards.
Maperalia

"Dave Peterson" wrote:

One of those variables isn't large enough to hold what you're trying to put into
it.

It might be as simple as changing:

dim WO as Integer
to
dim WO as Long

(but that's just a guess--without seeing the code and knowing the data, it's
difficult to say.)

maperalia wrote:

Dave;
Thanks for your response. I put the information but I got the following
error message:

Run-time error '6'
over flow

Then is hightligthing in the statement:

Filename = "" & WO & "_" & Tract & "_" & Supplier & "_" & mydatetime

Could you please tell me how to fix it please?

Regards.
Maperalia

"Dave Peterson" wrote:

So Dates and Time are variables that refer back to cells on a worksheet.

(I think I'd stay away from Time as a variable name.)

dim myDate as string
dim myTime as string
dim myDateTime as string

mydate = format(worksheets("sheet1").range("a1").value,"yyy ymmdd")
mytime = format(worksheets("sheet1").range("a2").value,"hhm m")

or if you have =now() in that cell:
mydatetime = format(worksheets("sheet1").range("a3").value,"yyy ymmdd_hhmm")

Then you could use:

Filename _
= "" & WO & "_" & Tract & "_" & Supplier & "_" & myDate & "_" & myTime

or
Filename = "" & WO & "_" & Tract & "_" & Supplier & "_" & mydatetime

=====
You've got to remove those slashes from the date and colons from the time.


maperalia wrote:

I have a VBA that has an statement:
Filename = "" & WO & "_" & Tract & "_" & Supplier & "_" & Dates & "_" & Time
& ""
I want to type the time in the excel cell ââ¬Å=now()ââ¬Â instead of typing:
Dates = 20050923 (September 23, 2005)
Time = 1145 ( 11:45AM)

Every time I type in the cell =Now() I have an error message that says ââ¬Åthe
file cannot be foundââ¬Â
Does anybody knows how to do it?

Thanks.
Maperalia

--

Dave Peterson


--

Dave Peterson

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
Cell("filename") doesn't update to new filename when do save as. Louis Excel Worksheet Functions 2 March 22nd 07 07:27 PM
set filename to <filename-date on open bob engler Excel Worksheet Functions 2 July 13th 06 05:11 AM
Filename with date and time Alan Excel Programming 2 October 5th 04 08:31 PM
Saving filename same as import filename Matt Excel Programming 4 February 24th 04 03:01 PM
Save Filename+Date+Time? Scooby912 Excel Programming 1 July 25th 03 06:21 PM


All times are GMT +1. The time now is 02:04 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright 2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"