473,406 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Vb-how To Insert Header In Logfile

Hi all,

Below are the codes which i wrote to monitor changes in excel. Now i wanted to add Header for the text file which will be generated. LIke suppose if change is happend in the row. i wanted to give name of the hader as "ROW". In the text file.

if changes are happening in the column i wanted to Name it as column.Kindly help me??

below are the codes :-
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
  3.    Dim W As Worksheet
  4.  
  5.    Set W = Sh
  6.  
  7.    Dim C As Range
  8.  
  9.    Dim Fnum As Long
  10.    Dim strFileName As String
  11.    strFileName = "C:\Documents and Settings\Anup\Desktop\book1.txt" & Format(Now(), "yyyy-mm-dd" & ".Txt")
  12.    Fnum = FreeFile
  13.    Open strFileName For Append Access Read Write Lock Write As #Fnum
  14.    For Each C In Target.Cells
  15.    With C
  16.       'Debug.Print , W.Name, .Column, .Row, .Value, .Value2,.Application.UserName
  17.       Print #Fnum, W.Name; vbTab; .Column; vbTab; .Row; vbTab; .Value; vbTab; Application.UserName; vbTab; Now(); vbTab
  18.    End With
  19.    Next
  20.  
  21.    Set W = Nothing
  22.  
  23.    Set C = Nothing
  24.  
  25.    Close #Fnum
  26.  
  27. End Sub
  28.  
May 25 '07 #1
5 1607
danp129
323 Expert 256MB
I'm not sure I understand. Every cell that's edited is going to have a Row and a Column that it exists in, so how do you plan to determine if it's a row edit instead of a column edit?
May 25 '07 #2
go thru the below example:-

this is the content of the file which is actually generated after change is made

AUDIT_PERSONALIZATION 1 104 5/21/2007 b 5/22/2007 5:50:01 PM
AUDIT_PERSONALIZATION 2 104 1 b 5/22/2007 5:50:01 PM

now i want this file to come up with header e.g

sheet name row column value date username
AUDIT_PERSONALIZATION 1 104 5/21/2007 b 5/22/2007 5:50:01 PM
AUDIT_PERSONALIZATION 2 104 1 b 5/22/2007 5:50:01 PM

Is there anyway??
May 28 '07 #3
Killer42
8,435 Expert 8TB
Why not just use Notepad or something, and create the file with your headers there already. Then your code can just append to the file.

Or if your code creates the file, it can simply write out the header line before writing the first line of "log info".

If you need to check whether there's anything in the file yet, after you open it you can use the Lof() function to get the current length (zero if it's empty).
May 28 '07 #4
Why not just use Notepad or something, and create the file with your headers there already. Then your code can just append to the file.

Or if your code creates the file, it can simply write out the header line before writing the first line of "log info".

If you need to check whether there's anything in the file yet, after you open it you can use the Lof() function to get the current length (zero if it's empty).

I can't use a format of file since this reports are generated on daily basis.

i think your second idea is correct. Can u plz guide me the code for writing the header line.As i am not aware of the code.
May 28 '07 #5
Killer42
8,435 Expert 8TB
Well, I don't know your circumstances very well, but it should be pretty simple, something like...

Expand|Select|Wrap|Line Numbers
  1. ' After opening the file for Append...
  2. If Lof(FileNum) = 0 Then
  3.   Print #FileNum, "sheet name row column value date username"
  4. End If
May 28 '07 #6

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

Similar topics

16
by: Terry | last post by:
Hi, I need some feedback. We are converting to .Net and we are trying to decide on whether to use VB.net or C#.net. As far as our current systems, they will probably be rewritten in ASP.Net. I...
5
by: Saga | last post by:
Hi all, I just read the thread by the same name posted on Jun 15, 9:45 AM, but I am looking at it from a different point of view. I came across this question in terms of functionality. Are VB and...
13
by: Arsalan | last post by:
Is there any advantage in C# over VB.NET ? Or the difference is only syntax ? Can anything done in C# which cannot be done in VB.NET?
34
by: Eric Wise | last post by:
Does anyone work for companies that actually implement both VB and C#? I know that you can do this in theory, I just find it hard to imagine that a company would split its programming technologies...
182
by: Jim Hubbard | last post by:
http://www.eweek.com/article2/0,1759,1774642,00.asp
2
by: D H | last post by:
Hi, Hi, I was looking for your opinion on VB.NET - its long-term prospects, etc. Sorry this is vague, but it's not meant to be a troll. It's a pro-VB.NET post actually. I haven't used VB or...
39
by: clintonG | last post by:
This is not about starting a fight but an observation that seems to be proving itself on its own merit and is therefore simply a point of conjecture. I did not get serious about writing software...
14
by: John Smith | last post by:
Can someone convert from C# into VB this line for me: if (c is System.Web.UI.HtmlControls.HtmlForm)
12
by: Striker | last post by:
I have never used VB, so sorry for the novice questions. I have a very small app in vba that only uses excel as a place to put a button and some code that I need to move to VB. Now it seems...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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,...

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.