473,699 Members | 2,600 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

writing to an external file

21 New Member
hey guys,

just a quickie that's probably been asked a million times, but i couldn't find it when searching so here goes:

i need to copy the contents of a word document and paste it to an external file (.txt) using VBA how do i go about doing this?

cheers Black Box
Nov 22 '06 #1
11 2618
albertw
267 Contributor
hey guys,

just a quickie that's probably been asked a million times, but i couldn't find it when searching so here goes:

i need to copy the contents of a word document and paste it to an external file (.txt) using VBA how do i go about doing this?

cheers Black Box
hi

try using menu Extra | macro | record New Macro
then perform a 'save as ...' as txt file.
close the recording and look what word has written (Alt+F11)

something like
Expand|Select|Wrap|Line Numbers
  1.  
  2.    ActiveDocument.SaveAs FileName:="NewName.txt", FileFormat:=wdFormatText, _
  3.         LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
  4.         :="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
  5.         SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
  6.         False
  7.  
  8.  
Nov 22 '06 #2
Blckbx
21 New Member
that's fine, but later i need to refer back to that text. how would i do that?

black box
Nov 22 '06 #3
albertw
267 Contributor
that's fine, but later i need to refer back to that text. how would i do that?

black box
hi if you want it accessed by VB you need only to use OPEN ...

Open "Newname.tx t" For Input As #1
While Not EOF(1)
Line Input #1, p
..
.. put any nice code here ..
..
Wend
Close #1
Nov 22 '06 #4
Blckbx
21 New Member
hate to be a pain but could you explan what each line of the code does, i don't just copy and paste code, i have to learn what it does.

Black box
Nov 22 '06 #5
albertw
267 Contributor
hate to be a pain but could you explan what each line of the code does, i don't just copy and paste code, i have to learn what it does.

Black box
hi here you go

Open "Newname.tx t" For Input As #1
opens the file you just wrote using the macro from previous mail for reading and call that #1

While Not EOF(1)
if the file has not ended (eof=end of file)

Line Input #1, p
then read a line and call that p

..
.. put any nice code here ..
don't know what you want to do with p
..

Wend
do so until you don't have any more lines in your file

Close #1
and don't forget to close, otherwise you can't open it again.
Nov 22 '06 #6
Blckbx
21 New Member
ok how can i apply this method to writing to the text file? the save as option doesn't quite do what i want.

black box
Nov 22 '06 #7
albertw
267 Contributor
ok how can i apply this method to writing to the text file? the save as option doesn't quite do what i want.

black box
hi

to avoid endless communication, can you provide me with info what you want to do in the textfile and how you want to save it again?
Nov 22 '06 #8
Blckbx
21 New Member
apollogies,

when i'm working on the text in a word document i want to make a backup so if i make a mistake i can come back to the original.

I need to copy the text out of the document, carry on working in that document and then copy the text back in.

any clearer?

black box
Nov 22 '06 #9
albertw
267 Contributor
apollogies,

when i'm working on the text in a word document i want to make a backup so if i make a mistake i can come back to the original.

I need to copy the text out of the document, carry on working in that document and then copy the text back in.

any clearer?

black box
yes ok, but why you want a backup as .txt file i don't see.
disadvantage of a textfile from word is, that you only save plain text.
why not set option to create always a backup file ?


[
Nov 22 '06 #10

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

Similar topics

4
9049
by: Igor Shulgin | last post by:
Hi! What is standard and direct way (within Oracle 9.2 stored procedures) for writing binary data from Oracle to external file on disk? We have tried to use UTL_FILE package, but it operates on files consisting out of "line" of size no more than 32767 bytes and adds new_line symbol upon closing files. Also we checked out interMedia types and packages for writing BLOB to disk but now we get stuck with some strange error messages.
1
2091
by: Andy Levy | last post by:
Hi I have an external .js file to my webpaage. Can i change the value of these variables from my htm page, so that they are changed for good. ie - i know this wont work, but it is an example. externalFile.js ------------- var alpha = "This is some text"
6
2010
by: Jeff Thies | last post by:
I've been thinking about writing CSS that's easy to read and adjust at a later date (often by someone else). Here's where I seem to be headed: Breaking the page down into container divs, setting a class for each of them like: ..header, .left_column, .main_content ,.right_column, .footer, .nav
3
3398
by: ishekar | last post by:
Hi, I have an application where i want to write data to a file, the data is being sent from an external source. I know the total size of the data and then i retrieve the data in small segments from the source. This data is written to file in a loop. My question. 1. Will it be useful to increase the file size initially then seek to 0 and start writing to file. whether there will be any performance improvements
1
8411
by: Aravind | last post by:
we have two files: 1. rc4.c (defines one function "create_pin()") 2. MyImpl.c(calling the function "create_pin()"),This implements JNI method. 1.When I am trying to create .dll file with one file rc4.obj(rc4.c),it is creating the .dll file without any error. Command : ILINK32 rc4.obj 2.But,when we are trying to create .dll file with two .obj files with following errors.
5
3630
by: snicks | last post by:
I'm trying to exec a program external to my ASP.NET app using the following code. The external app is a VB.NET application. Dim sPPTOut As String sPPTOut = MDEPDirStr + sID + ".ppt" Dim p As New System.Diagnostics.Process 'p.Start(MDEPDirStr & "macrun.exe", sPPTOut) p.Start("C:\WINDOWS\SYSTEM32\CALC.EXE") 'p.Start("C:\WINDOWS\SYSTEM32\macrun.exe", sPPTOut)
16
7181
by: Claudio Grondi | last post by:
I have a 250 Gbyte file (occupies the whole hard drive space) and want to change only eight bytes in this file at a given offset of appr. 200 Gbyte (all other data in that file should remain unchanged). How can I do that in Python? Claudio Grondi
2
5324
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: 1>make_buildinfo.obj : error LNK2019: unresolved external symbol __imp__RegQueryValueExA@24 referenced in function _make_buildinfo2 Ask on python-list@python.org . - Josiah
2
6138
by: murthydb2 | last post by:
Hi My requirement is that i have to write a stored procedure in db2 and that will be executed in a batch file . Any system error or validation error that occurs inside the db2 sp during the execution need to be written in external flat file ( Log file to know the error ) . Is there anything similar in db2 like UTL_FILE in oracle . Please find the sample coding in oracle which will write the output to a external flat...
0
1246
by: xahlee | last post by:
Here's a little tutorial that lets you write emacs commands for processing the current text selection in emacs in your favorite lang. Elisp Wrapper For Perl Scripts http://xahlee.org/emacs/elisp_perl_wrapper.html plain text version follows. ------------------------------------- Elisp Wrapper For Perl Scripts
0
8623
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
9197
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9054
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...
1
8941
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8897
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...
0
7785
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4390
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...
0
4637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2015
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.