473,770 Members | 6,978 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Script to insert text into text file

4 New Member
HI folks,

I'm a chem engineer with no VB programming knowledge (as you'll see from my question!)

I want a script to open a .txt file, insert pre-defined text into the start and end of the file, then close teh saved file with a .nc extension.

I'd like to have this as a batch file or exe file which i can installt o run from my users desktops.

I tried doing it in Word using macros and the FileDialog thingy to bring up dialogs for the user to select his files but it would not save for me and I couldn;t figure how to get it outside of Word. Code below.
Expand|Select|Wrap|Line Numbers
  1. ' Test1 Macro
  2. ' To open FIle-Open dialog box
  3.     With Dialogs(wdDialogFileOpen)
  4.     .Name = "*.txt"
  5.     .Show
  6.     End With
  7. ' To insert the text
  8.     Selection.TypeParagraph
  9.     Selection.TypeParagraph
  10.     Selection.TypeParagraph
  11.     Selection.HomeKey Unit:=wdStory
  12.     Selection.TypeText Text:="The next line sends a 'Change State' command to system"
  13.     Selection.TypeParagraph
  14.     Selection.TypeText Text:="M3"
  15.     Selection.TypeParagraph
  16.     Selection.TypeText Text:="The next line tells system to Dwell for 5 seconds"
  17.     Selection.TypeParagraph
  18.     Selection.TypeText Text:="G04H5"
  19.  
  20. 'This is where the error occurs  
  21. With Dialogs(wdDialogFileSave)
  22.     .Name = "*.*"
  23.     .Show
  24. End With
  25.  
  26. End Sub
  27.  
Help greatly appreciated
Jan 22 '07 #1
2 4296
Dököll
2,364 Recognized Expert Top Contributor
Hello Mr. Hynes!

I am may have a simpler solution program for you. Are you typing in the text or will the text be added by your form load?

I am keeping a log of your message to ensure I get to it whn needed. I have an example program here fro the college, may be helpful to you.

Dököll
Feb 3 '07 #2
Killer42
8,435 Recognized Expert Expert
If the text is the same every time, you could probably something with a batch file. I'm thinking something along the lines of...
Expand|Select|Wrap|Line Numbers
  1. COPY HeaderStuff.Txt+YourTextFile.txt+FooterStuff.Txt YourTextFile.nc
...or, if you can provide the input file name as a parameter to the batch file...
Expand|Select|Wrap|Line Numbers
  1. COPY HeaderStuff.Txt+%1+FooterStuff.Txt %1.nc
This one would produce a modified copy with .nc added onto the end of the existing filename and extension - Eg. YourTextFile.tx t.nc.
Feb 4 '07 #3

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

Similar topics

2
2468
by: \(a\) | last post by:
I've got a cgi script that allows me to add the output of a php script to an html page using the following line of code. #insert : http://www.url.com/sript.php# What I'm wondering is if someone could write me a couple of lines of code for script.php that would randomly select one line of information from a text file called text.txt. This way, if I had the following line in my html file, the place where
0
3076
by: Marc de Winter | last post by:
Hello all, I hope someone on this group can help me, even though this is kind of a specific question about a (widely used) script. It's the NMS-WWWBOARD script. Formerly from "Matt's Script Archive", but now it's rewritten and supposedly better working. You can find it here: http://www.scriptarchive.com/nms.html
1
740
by: JStrummer | last post by:
Any recommendations on how to generate an INSERT SQL script for the records in a tab-delimietd text file? The limitation is that, while I do have command-line mySQL access locally, I do not at my remote host, so I will need to come up with a solution that I can run via something like phpmyadmin, mysqlcc, or TOAD for mySQL. Any help would be appreciated.
4
2231
by: Scott Baxter | last post by:
Hello, I got the following scripts to upload files to my directories I call insert.htm Browse for a file, then click 'submit' It works for small files, and for a small .mdb (access file)
8
4687
by: Jakej | last post by:
I've been using a javascript in an html file for a banner slider, and it works as desired. But I'd like to use it on more than one page and it would be great if I could transfer the code to a .js file and call it with the <script src="filename.js"></script> tags as I do for many other .js files. But, when I try to do that way, it doesn't work right. It will display the banner text, but only on the 0,0 page coordinate and doesn't slide....
4
1801
by: Jake j | last post by:
To those of you who sent me working examples of js include routines, much thanks. I see from them examples that what I'm trying to get to requires a higher level of js knowledge than I've got. Here's what I'm really trying to do: I've been using a sliding banner javascript routine in several html files and it works fine. Rather than duplicate the code in each file, however, it would obviously be preferable to including the routine in...
9
6690
by: Yaro | last post by:
Hello DB2/NT 8.1.3 Sorry for stupid questions. I am newbe in DB2. 1. How can I read *.sql script (with table and function definitions) into a database? Tool, command... 2. In Project Center I created funcion CREATE FUNCTION DB2ADMIN.xxx( )
7
1468
by: farsad nasseri | last post by:
Hi I have written a small transformation routine that converts my XML file into a bunch of Insert statements in another file. The file will be in the following format but much longer: INSERT INTO lockbox_refid (lockbox_refid) VALUES ('lasfgasd '); INSERT INTO lockbox_refid (lockbox_refid)
4
3083
by: Kim | last post by:
Random image downloader for specified newsgroup. Hi I'm writing a small script that will download random images from a specified newsgroup. I've imported yenc into the script but I can't open the image or save it. This is my first script so be gentle! Heres the script ####random group downloader#### import nntplib import string, random import mimetools import StringIO
0
9591
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10057
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9869
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7415
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5312
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3575
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.