473,320 Members | 1,802 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,320 software developers and data experts.

writing to an external file

21
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 2598
albertw
267 100+
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
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 100+
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.txt" 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
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 100+
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.txt" 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
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 100+
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
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 100+
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
Blckbx
21
ok maybe backup was the wrong choice of words,

i'm making a cryptanalysis script which involves guessing to an extent, so if i guess the wrong set of characters and VB carries on manipulating the text and writing to the document, i want to be able to go back to the old text. so plain text is the only thing i want to be able to recover.

Black box
Nov 22 '06 #11
albertw
267 100+
ok maybe backup was the wrong choice of words,

i'm making a cryptanalysis script which involves guessing to an extent, so if i guess the wrong set of characters and VB carries on manipulating the text and writing to the document, i want to be able to go back to the old text. so plain text is the only thing i want to be able to recover.

Black box

hi

Expand|Select|Wrap|Line Numbers
  1. Private Sub document_close()
  2. ActiveDocument.SaveAs FileName:="Original.doc", fileformat:=wdFormatDocument
  3. ActiveDocument.SaveAs FileName:="BackUp.txt", fileformat:=wdFormatText
  4. End Sub
  5.  
put this code in your codepage belonging to ThisDocument (NOT the module)


the document will be saved as "backup.txt" and as "original.doc", when closing the document
Nov 22 '06 #12

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

Similar topics

4
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...
1
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...
6
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,...
3
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...
1
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...
5
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...
16
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...
2
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: ...
2
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...
0
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.