VBA on MS Word - Save Append Log file

shabeersa

New Member
Joined
Apr 22, 2013
Messages
5
Hi There

I created a MS Word Macro enable document to update the users Outlook Email Signature and copy it to the Email location. All this is working

Now I Want to save values to a Text file (log file) but it must append the text entry into one main "Report.txt"

I got the code to save, below:
Code:
[COLOR=#0000FF][FONT='inherit']Sub [/FONT][/COLOR][COLOR=#444444][FONT='inherit']Example1()[/FONT][/COLOR]
[COLOR=#444444][FONT='inherit'][COLOR=#00B400][FONT=inherit]'the final string to print in the text file [/FONT][/COLOR]
[/FONT][/COLOR][COLOR=#444444][FONT='inherit'][COLOR=#0000FF][FONT=inherit]Dim [/FONT][/COLOR]strData [COLOR=#0000FF][FONT=inherit]As [/FONT][/COLOR][COLOR=#0000FF][FONT=inherit]String [/FONT][/COLOR]
[/FONT][/COLOR][COLOR=#444444][FONT='inherit'][COLOR=#00B400][FONT=inherit]'each line in the original text file [/FONT][/COLOR]
[/FONT][/COLOR][COLOR=#444444][FONT='inherit'][COLOR=#0000FF][FONT=inherit]Dim [/FONT][/COLOR]strLine [COLOR=#0000FF][FONT=inherit]As [/FONT][/COLOR][COLOR=#0000FF][FONT=inherit]String [/FONT][/COLOR]
[/FONT][/COLOR][COLOR=#444444][FONT='inherit']strData = ""
[/FONT][/COLOR][COLOR=#444444][FONT='inherit'][COLOR=#00B400][FONT=inherit]'open the original text file to read the lines [/FONT][/COLOR]
[/FONT][/COLOR][COLOR=#444444][FONT='inherit'][COLOR=#0000FF][FONT=inherit]Open [/FONT][/COLOR]"[FONT=Verdana]\\172.16.1.41\Apps\Report.txt[/FONT]" [COLOR=#0000FF][FONT=inherit]For [/FONT][/COLOR][COLOR=#0000FF][FONT=inherit]Input [/FONT][/COLOR][COLOR=#0000FF][FONT=inherit]As [/FONT][/COLOR]#1
[/FONT][/COLOR][COLOR=#444444][FONT='inherit'][COLOR=#00B400][FONT=inherit]'continue until the end of the file [/FONT][/COLOR]
[/FONT][/COLOR][COLOR=#444444][FONT='inherit'][COLOR=#0000FF][FONT=inherit]While [/FONT][/COLOR]EOF(1) = [COLOR=#0000FF][FONT=inherit]False[/FONT][/COLOR]
[/FONT][/COLOR][COLOR=#444444][FONT='inherit']    [COLOR=#00B400][FONT=inherit]'read the current line of text [/FONT][/COLOR][/FONT][/COLOR]
[COLOR=#444444][FONT='inherit'][COLOR=#0000FF][FONT=inherit]    Line [/FONT][/COLOR][COLOR=#0000FF][FONT=inherit]Input [/FONT][/COLOR]#1, strLine [/FONT][/COLOR]
[COLOR=#444444][FONT='inherit']    [COLOR=#00B400][FONT=inherit]'add the current line to strData [/FONT][/COLOR][/FONT][/COLOR]
[COLOR=#444444][FONT='inherit']    strData = strData + strLine & vbCrLf [/FONT][/COLOR]
[COLOR=#444444][FONT='inherit'][COLOR=#0000FF][FONT=inherit]Wend [/FONT][/COLOR]
[/FONT][/COLOR][COLOR=#444444][FONT='inherit'][COLOR=#00B400][FONT=inherit]'add the new line [/FONT][/COLOR]
[/FONT][/COLOR][COLOR=#444444][FONT='inherit']strData = strData + "Data to be appended"
[/FONT][/COLOR][COLOR=#444444][FONT='inherit'][COLOR=#0000FF][FONT=inherit]Close [/FONT][/COLOR]#1
[/FONT][/COLOR][COLOR=#444444][FONT='inherit'][COLOR=#00B400][FONT=inherit]'reopen the file for output [/FONT][/COLOR]
[/FONT][/COLOR][COLOR=#444444][FONT='inherit'][COLOR=#0000FF][FONT=inherit]Open [/FONT][/COLOR]"[FONT=Verdana]\\172.16.1.41\Apps\Report.txt[/FONT]" [COLOR=#0000FF][FONT=inherit]For [/FONT][/COLOR]Output [COLOR=#0000FF][FONT=inherit]As [/FONT][/COLOR]#1
[/FONT][/COLOR][COLOR=#444444][FONT='inherit'][COLOR=#0000FF][FONT=inherit]Print [/FONT][/COLOR]#1, strData
[/FONT][/COLOR][COLOR=#444444][FONT='inherit'][COLOR=#0000FF][FONT=inherit]Close [/FONT][/COLOR]#1
[/FONT][/COLOR][COLOR=#444444][FONT='inherit'][COLOR=#0000FF][FONT=inherit]End [/FONT][/COLOR][COLOR=#0000FF][FONT=inherit]Sub [/FONT][/COLOR][/FONT][/COLOR]

I want it to save to: \\172.16.1.41\Apps\Report.txt

However i also want the following values from the VBA :
1) Textbox1 Value - Which is on the UserForm, its the Person Full Name
2) Username - The Username is on the code under "Module1" called : & Environ("username")
3) Date & Time Stamp - The current Date And Time Stamp when the entry save

Attached Sample of the Report.txt file

The Word Document also attached. I want this code to go as a new Macro. So i can call it on Submit button later.

Download Here:
Word Document File
https://ufile.io/4pesw

Report.txt
https://ufile.io/is1lk

Regards
ShabeerSA
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top