Home |
Search |
Today's Posts |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Jul 27, 6:16*am, "Rick Rothstein \(MVP - VB\)"
wrote: Just change the assignment for the FileNameAndPath variable from this.... to this... FileNameAndPath = "c:\Dir1\Dir2\etc\" & .Range("E5").Value & "(" & _ Date$ & ")(" & Replace(Time$, ":", "-") & ").txt" I replaced the FileNameAndPath and when I run the macro it highlights .Range("E5") and gives the following error: Invalid or unqualified reference I forgot to mention that you needed to move the line down one so it was inside the With/End With block. See the full code with all the modifications after my signature (you can copy/paste it). I wish to have the name to be in the following format: 1234 27072008 11:36 pm.txt You can't have it in that format... the colon (:) is an illegal character in a filename. I'll use a dash, but as I said in my previous post, you can change the dash to some other **legal** filename character. Here is a link describing how to make a legal filename... http://msdn.microsoft.com/library/de...ary/en-us/file.... Rick Sub WriteDataOut() * Dim X As Long * Dim FF As Long * Dim LastRow As Long * Dim Dte As String * Dim Record As String * Dim TotalFile As String * Dim FileNameAndPath As String * With Worksheets("Sheet1") * * FileNameAndPath = "c:\Dir1\Dir2\etc\" & .Range("E5").Value & _ * * * * * * * * * * * * * * Format(Now, " ddmmyyyy ") & _ * * * * * * * * * * * * * * Format(Now, "hh-mm am/pm") & ".txt" * * LastRow = .Cells(Rows.Count, "C").End(xlUp).Row * * For X = 10 To LastRow * * * Record = Space$(66) * * * Mid$(Record, 1) = .Cells(X, "C").Value * * * Mid$(Record, 10) = Format$(.Cells(X, "F").Value, "0000000000") * * * Dte = .Cells(X, "H").Value * * * Mid$(Record, 20) = Right$(Dte, 4) & Mid$(Dte, 4, 2) & Left$(Dte, 2) * * * Dte = .Cells(X, "H").Value * * * Mid$(Record, 28) = Right$(Dte, 4) & Mid$(Dte, 4, 2) & Left$(Dte, 2) * * * Mid$(Record, 36) = Format$(100 * Abs(.Cells(X, "K").Value) _ * * * * * * * * * * * * * * * * * * * * * * * , "000000000000000") * * * Mid$(Record, 51) = .Cells(X, "L").Value * * * Mid$(Record, 56) = .Cells(X, "Q").Value * * * TotalFile = TotalFile & vbCrLf & Record * * Next * * FF = FreeFile * * Open FileNameAndPath For Output As #FF * * Print #FF, TotalFile * * Close #FF * End With End Sub Thanks Rick. Works great. You are really helpful Rushna |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Excel - CSV file, trying to save a date as text, reverts back to d | Excel Worksheet Functions | |||
customer date time save file | Excel Discussion (Misc queries) | |||
Save File with Date and Time Stamp | Excel Programming | |||
Macro to save Excel file with date and time in the file name? | Excel Programming | |||
Date stamped comment box | Excel Programming |