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!

Help with exporting to CSV file - need seperate file names for records

Status
Not open for further replies.

terrielee

Programmer
May 11, 2011
3
US
I am attempting to use a wizard to output a table in .csv format to several folders each day. The wizard has the ability to run each day but always saves under that same name. Is there a way to get a unique file name for each ticket that is in the file?? Or even better File ticket number 1, MM/DD/YY, File ticket number 2, MM/dd/yy etc....
 


Hi,

What application?

WHat version?

Where is your code?

Short answer...
Code:
msgbox "Some text" & Format(Date,"yy-mm-dd")


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
You could do something like this...

Public Sub SaveCSV_AsXls()
Dim acpc As String, acpx As String, fac As String, xlsDir As String
Dim Well_Name_Short As String, Well_Name_Long As String

Select Case ActiveWorkbook.FileFormat
Case Is <> 6, 22, 23, 24
'MsgBox "Not a CSV"
Exit Sub
End Select


'disable viewing
Application.DisplayAlerts = False
Application.ScreenUpdating = False

'csv path and name
acpc = ActiveWorkbook.Path & "\" & ActiveWorkbook.Name

'well name
On Error Resume Next
fac = ActiveSheet.Cells.Find(what:="Facility", after:=Range(Cells(1, 1).Address), LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Address

If fac <> "" Then
Well_Name_Short = ActiveSheet.Cells(Range(fac).Row, Range(fac).Column + 1).Value
Else
Well_Name_Short = "Not Found"
End If

Well_Name_Long = "Survey Data_" & Well_Name_Short & ".xls"

'save as xls
ActiveWorkbook.SaveAs FileFormat:=xlExcel8

'path and name of new book
acpx = ActiveWorkbook.Path & "\" & ActiveWorkbook.Name

'close it
ActiveWorkbook.Close SaveChanges:=False

'set dir
xlsDir = Environ("USERPROFILE") & "\Desktop\Morning Reports\"

'if Morning Reports does not exist create it
If Len(Dir(xlsDir, vbDirectory)) = 0 Then
MkDir Environ("USERPROFILE") & "\Desktop\Morning Reports\"
End If

'delete csv and any older morning report
Kill acpc
Kill xlsDir & Well_Name_Long

'move file from temp folder to Morning Report
Name acpx As xlsDir & Well_Name_Long

'enable viewing
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub




OCD, it’s not obsessive if you can control it…
 
Thanks, You folks ROCK! I'll give it a try....let ya know how it goes.

Just wanna get this thing finished. :)
 
I just noticed your reference to "Well_Name" and Facility, also morning reports. Reminds me of Chevron days.

I'm doing this upload for another "bigge" in the petro business. FYI.

I'll get back with you and let you know how this work for me. I sure appreciate your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top