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

How to save word doc in text file in any location

Hi All,

I wanted to save my word file into text format using macro in word 2007.

Below snippet code for saving doc into text but we in below code we are giving path and i wanted to run this macro for any doc in any path.

Expand|Select|Wrap|Line Numbers
  1. Sub Macro4()
  2. '
  3. ' Macro4 Macro
  4. '
  5. '
  6.     ChangeFileOpenDirectory "C:\Documents and Settings\User\Desktop\Reverend\"
  7.     ActiveDocument.SaveAs FileName:="Chapter 1.txt", FileFormat:=wdFormatText, _
  8.          LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
  9.         :="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
  10.         SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
  11.         False, Encoding:=65001, InsertLineBreaks:=False, AllowSubstitutions:= _
  12.         False, LineEnding:=wdCRLF
  13. End Sub
  14.  
Nov 10 '13 #1
1 2107
Any way i just got.

Expand|Select|Wrap|Line Numbers
  1. Sub ChangeDocsToTxtOrRTFOrHTML()
  2. 'with export to PDF in Word 2007
  3.     Dim fs As Object
  4.     Dim oFolder As Object
  5.     Dim tFolder As Object
  6.     Dim oFile As Object
  7.     Dim strDocName As String
  8.     Dim intPos As Integer
  9.     Dim locFolder As String
  10.     Dim fileType As String
  11.     On Error Resume Next
  12.     locFolder = InputBox("Enter the folder path to DOCs", "File Conversion", "C:\Documents and Settings\kamlesh.singh\Desktop\New Folder")
  13.     Select Case Application.Version
  14.         Case Is < 12
  15.             Do
  16.                 fileType = UCase(InputBox("Change DOC to TXT, RTF, HTML", "File Conversion", "TXT"))
  17.             Loop Until (fileType = "TXT" Or fileType = "RTF" Or fileType = "HTML")
  18.         Case Is >= 12
  19.             Do
  20.                 fileType = UCase(InputBox("Change DOC to TXT, RTF, HTML or PDF(2007+ only)", "File Conversion", "TXT"))
  21.             Loop Until (fileType = "TXT" Or fileType = "RTF" Or fileType = "HTML" Or fileType = "PDF")
  22.     End Select
  23.     Application.ScreenUpdating = False
  24.     Set fs = CreateObject("Scripting.FileSystemObject")
  25.     Set oFolder = fs.GetFolder(locFolder)
  26.     Set tFolder = fs.CreateFolder(locFolder & "Converted")
  27.     Set tFolder = fs.GetFolder(locFolder & "Converted")
  28.     For Each oFile In oFolder.Files
  29.         Dim d As Document
  30.         Set d = Application.Documents.Open(oFile.Path)
  31.         strDocName = ActiveDocument.Name
  32.         intPos = InStrRev(strDocName, ".")
  33.         strDocName = Left(strDocName, intPos - 1)
  34.         ChangeFileOpenDirectory tFolder
  35.         Select Case fileType
  36.         Case Is = "TXT"
  37.             strDocName = strDocName & ".txt"
  38.             ActiveDocument.SaveAs FileName:=strDocName, FileFormat:=wdFormatText
  39.         Case Is = "RTF"
  40.             strDocName = strDocName & ".rtf"
  41.             ActiveDocument.SaveAs FileName:=strDocName, FileFormat:=wdFormatRTF
  42.         Case Is = "HTML"
  43.             strDocName = strDocName & ".html"
  44.             ActiveDocument.SaveAs FileName:=strDocName, FileFormat:=wdFormatFilteredHTML
  45.         Case Is = "PDF"
  46.             strDocName = strDocName & ".pdf"
  47.  
  48.             ' *** Word 2007 users - remove the apostrophe at the start of the next line ***
  49.             'ActiveDocument.ExportAsFixedFormat OutputFileName:=strDocName, ExportFormat:=wdExportFormatPDF
  50.  
  51.         End Select
  52.         d.Close
  53.         ChangeFileOpenDirectory oFolder
  54.     Next oFile
  55.     Application.ScreenUpdating = True
  56. End Sub
  57.  
Nov 12 '13 #2

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

Similar topics

3
by: Dynamo | last post by:
Hi all I want to save the contents of a textarea within my webform as a text file .txt on my webserver. In addition, I want to save it with the same file name as the next autoincrement number in...
1
by: Shahzad Atta | last post by:
Hi there, I need to save a word.doc file in html format. Any help will be appreciated. Best Regards, Shahzad Atta.
5
by: Vicky | last post by:
Hi, I Apologise if this has been covered however I have hit a small stumbling block. I have currently created a program which, depending upon the variables displays totals etc.. on a screen...
11
by: Thomas Magma | last post by:
I have a simple JavaScript application that will generate some text type data for the end user. Is it possible to have a button that will allow them to save this information to a text file? ...
1
by: Digi4 | last post by:
Hi ! I have to save a word/text document in the database directly using VB.NET and MySql.And also to retrieve it directly from the database. I have chosen Blob datatype for it, but I dont know...
2
by: nuhura01 | last post by:
Hi.. I'm trying to save query path which is in text box to text file. Below is the coding that i'm using currently: Private Sub SaveQueryPath() 'save to text file Response.Clear()...
1
by: papafreebird | last post by:
I would like to save the contents of a wxListBox to a text file. Using borland c++ builder I am able to accomplish this by using the following code ListBox1->Items->GetText(); ...
3
by: lerougegorge | last post by:
When I pull a string from a UTF-8 encoded field in my SQL, I get a string like the following: "& #2342;& #2369;& #2312;" (I have inserted a space between "&" and "#" to stop this from...
1
by: AccessHunter | last post by:
Hi, I have written a code to display the Save As dialog box for my users, with a default file name. The code works and displays the dialog box with the default name. But when I click the Save...
2
by: ahmurad | last post by:
Dear Brothers, I am using a 'text file location' at my code to read the file contents- which is working fine in my local server. The web contents/php files and the specified txt file are at the...
1
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.