Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Add .LOG to .txt file on creation


Hi,
In using this code to create and copy data to a .txt file.

I want to (on the inital creation of the file ONLY) insert .LOG

as the first line.


Code:
--------------------
Sub TxtFile()
Dim rrr
Dim MyTest99
Dim MyData
rrr = FreeFile
MyData = Selection

'On only the inital creation of the txt file, I want .LOG inserted

MyTest99 = "E:\backup & testing\test99.txt"
Open MyTest99 For Append Shared As #rrr
Print #rrr, MyData
Close #rrr
End Sub
--------------------

Any direction appreciated.
Dave


--
Piranha
------------------------------------------------------------------------
Piranha's Profile: http://www.excelforum.com/member.php...o&userid=20435
View this thread: http://www.excelforum.com/showthread...hreadid=480975

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Add .LOG to .txt file on creation


Hello Piranha,


Code:
--------------------

Sub TxtFile()
Dim rrr
Dim MyTest99
Dim MyData
rrr = FreeFile
MyData = Selection

'On only the inital creation of the txt file, I want .LOG inserted
MyTest99 = "E:\backup & testing\test99"

'Test if .log file exists - Append will create the file if it doesn't exist
If Dir(MyTest99 & ".log") Then
Name MyTest & ".log" As MyTest99 & ".txt"
MyTest99 = MyTest99 & ".txt"
Else
MyTest99 = MyTest99 & ".log"
End If

Open MyTest99 For Append Shared As #rrr
Print #rrr, MyData
Close #rrr
End Sub

--------------------

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=480975

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Add .LOG to .txt file on creation


Hello Piranha,


Code
-------------------

Sub TxtFile()
Dim rrr
Dim MyTest99
Dim MyData
rrr = FreeFile
MyData = Selection

'On only the inital creation of the txt file, I want .LOG inserted
MyTest99 = "E:\backup & testing\test99"

'Test if .log file exists - Append will create the file if it doesn't exist
If Dir(MyTest99 & ".log") Then
Name MyTest & ".log" As MyTest99 & ".txt"
MyTest99 = MyTest99 & ".txt"
Else
MyTest99 = MyTest99 & ".log"
End If

Open MyTest99 For Append Shared As #rrr
Print #rrr, MyData
Close #rrr
End Sub

-------------------

Sincerely,
Leith Ros

--
Leith Ros
-----------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...fo&userid=1846
View this thread: http://www.excelforum.com/showthread.php?threadid=48097

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Add .LOG to .txt file on creation

I read your post slightly differently. You want .LOG inserted as the first line
of a .txt file when it is created?

Option Explicit
Sub TxtFile()
Dim rrr As Long
Dim MyTest99 As String
Dim MyData As String
Dim testStr As String

rrr = FreeFile
MyData = Selection.Cells(1).Value
MyTest99 = "E:\backup & testing\test99.txt"

'assumes that the drive/folder exists
testStr = ""
On Error Resume Next
testStr = Dir(MyTest99)
On Error GoTo 0

Open MyTest99 For Append As #rrr
If testStr = "" Then
Print #rrr, ".LOG"
End If
Print #rrr, MyData
Close #rrr
End Sub


A neat way to keep track of time/dates in Text files.

(A hidden feature with notepad if anyone wants to see what it does.)

Piranha wrote:

Hi,
In using this code to create and copy data to a .txt file.

I want to (on the inital creation of the file ONLY) insert .LOG

as the first line.

Code:
--------------------
Sub TxtFile()
Dim rrr
Dim MyTest99
Dim MyData
rrr = FreeFile
MyData = Selection

'On only the inital creation of the txt file, I want .LOG inserted

MyTest99 = "E:\backup & testing\test99.txt"
Open MyTest99 For Append Shared As #rrr
Print #rrr, MyData
Close #rrr
End Sub
--------------------

Any direction appreciated.
Dave

--
Piranha
------------------------------------------------------------------------
Piranha's Profile: http://www.excelforum.com/member.php...o&userid=20435
View this thread: http://www.excelforum.com/showthread...hreadid=480975


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Add .LOG to .txt file on creation


Hi Leith & Dave,

Leith, I can't get past this line with your code.

Code:
--------------------
If Dir(MyTest99 & ".log") Then
--------------------
I am going to keep
playing with it though

Dave, Exactly what i want. I am going to make the selection
part, to copy the entire selection instead of one cell and i will be
done.

Thx guys, very much appricated.
Dave Peterson Wrote:
I read your post slightly differently. You want .LOG inserted as the
first line
of a .txt file when it is created?

Option Explicit
Sub TxtFile()
Dim rrr As Long
Dim MyTest99 As String
Dim MyData As String
Dim testStr As String

rrr = FreeFile
MyData = Selection.Cells(1).Value
MyTest99 = "E:\backup & testing\test99.txt"

'assumes that the drive/folder exists
testStr = ""
On Error Resume Next
testStr = Dir(MyTest99)
On Error GoTo 0

Open MyTest99 For Append As #rrr
If testStr = "" Then
Print #rrr, ".LOG"
End If
Print #rrr, MyData
Close #rrr
End Sub


A neat way to keep track of time/dates in Text files.

(A hidden feature with notepad if anyone wants to see what it does.)

Piranha wrote:

Hi,
In using this code to create and copy data to a .txt file.

I want to (on the inital creation of the file ONLY) insert .LOG

as the first line.

Code:
--------------------
Sub TxtFile()
Dim rrr
Dim MyTest99
Dim MyData
rrr = FreeFile
MyData = Selection

'On only the inital creation of the txt file, I want .LOG inserted

MyTest99 = "E:\backup & testing\test99.txt"
Open MyTest99 For Append Shared As #rrr
Print #rrr, MyData
Close #rrr
End Sub
--------------------

Any direction appreciated.
Dave

--
Piranha

------------------------------------------------------------------------
Piranha's Profile:

http://www.excelforum.com/member.php...o&userid=20435
View this thread:

http://www.excelforum.com/showthread...hreadid=480975

--

Dave Peterson



--
Piranha
------------------------------------------------------------------------
Piranha's Profile: http://www.excelforum.com/member.php...o&userid=20435
View this thread: http://www.excelforum.com/showthread...hreadid=480975



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Add .LOG to .txt file on creation


Hello Piranha,

Looks like I got it wrong. Sorry. What's the question about my line o
code?

Sincerely,
Leith Ros

--
Leith Ros
-----------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...fo&userid=1846
View this thread: http://www.excelforum.com/showthread.php?threadid=48097

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Add .LOG to .txt file on creation


Leith Ross Wrote:
Hello Piranha,

Looks like I got it wrong. Sorry. What's the question about my line of
code?

Sincerely,
Leith RossHi Leith,

I get a 'Type Mismatch' on this line.

Code:
--------------------
If Dir(MyTest99 & ".log") Then
--------------------
Dave


--
Piranha
------------------------------------------------------------------------
Piranha's Profile: http://www.excelforum.com/member.php...o&userid=20435
View this thread: http://www.excelforum.com/showthread...hreadid=480975

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Add .LOG to .txt file on creation


Hello Piranha,

I am striking out with you. I didn't correct that line like I thought I
had when I posted it. It should be...

If Dir(MyTest99 & ".log") < ""Then

The purpose is check if the file has a ".log" extension (first time it
was created). I mistakenly thought you want the file to have a ".log"
extension only after it was first created. After being accessed the
second time to then change the ".log" extension to ".txt" (presumably
as a measure of security - so I thought). Anyway, the code may not be a
total loss if you can get something useful from it.

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=480975

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
*.tmp file creation in Excel Yvonne Excel Discussion (Misc queries) 3 July 8th 07 12:58 PM
Would Like to Automate Batch File Creation and Text FIle Import socrtwo Excel Discussion (Misc queries) 2 August 18th 06 03:54 PM
file creation date munken Excel Worksheet Functions 2 August 31st 05 01:40 PM
PDF file creation CraigCC Excel Programming 4 June 4th 05 12:20 PM
File List Creation robert Excel Programming 2 November 4th 03 07:56 PM


All times are GMT +1. The time now is 05:15 PM.

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"