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. -
Sub Macro4()
-
'
-
' Macro4 Macro
-
'
-
'
-
ChangeFileOpenDirectory "C:\Documents and Settings\User\Desktop\Reverend\"
-
ActiveDocument.SaveAs FileName:="Chapter 1.txt", FileFormat:=wdFormatText, _
-
LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
-
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
-
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
-
False, Encoding:=65001, InsertLineBreaks:=False, AllowSubstitutions:= _
-
False, LineEnding:=wdCRLF
-
End Sub
-
1 2107
Any way i just got. -
Sub ChangeDocsToTxtOrRTFOrHTML()
-
'with export to PDF in Word 2007
-
Dim fs As Object
-
Dim oFolder As Object
-
Dim tFolder As Object
-
Dim oFile As Object
-
Dim strDocName As String
-
Dim intPos As Integer
-
Dim locFolder As String
-
Dim fileType As String
-
On Error Resume Next
-
locFolder = InputBox("Enter the folder path to DOCs", "File Conversion", "C:\Documents and Settings\kamlesh.singh\Desktop\New Folder")
-
Select Case Application.Version
-
Case Is < 12
-
Do
-
fileType = UCase(InputBox("Change DOC to TXT, RTF, HTML", "File Conversion", "TXT"))
-
Loop Until (fileType = "TXT" Or fileType = "RTF" Or fileType = "HTML")
-
Case Is >= 12
-
Do
-
fileType = UCase(InputBox("Change DOC to TXT, RTF, HTML or PDF(2007+ only)", "File Conversion", "TXT"))
-
Loop Until (fileType = "TXT" Or fileType = "RTF" Or fileType = "HTML" Or fileType = "PDF")
-
End Select
-
Application.ScreenUpdating = False
-
Set fs = CreateObject("Scripting.FileSystemObject")
-
Set oFolder = fs.GetFolder(locFolder)
-
Set tFolder = fs.CreateFolder(locFolder & "Converted")
-
Set tFolder = fs.GetFolder(locFolder & "Converted")
-
For Each oFile In oFolder.Files
-
Dim d As Document
-
Set d = Application.Documents.Open(oFile.Path)
-
strDocName = ActiveDocument.Name
-
intPos = InStrRev(strDocName, ".")
-
strDocName = Left(strDocName, intPos - 1)
-
ChangeFileOpenDirectory tFolder
-
Select Case fileType
-
Case Is = "TXT"
-
strDocName = strDocName & ".txt"
-
ActiveDocument.SaveAs FileName:=strDocName, FileFormat:=wdFormatText
-
Case Is = "RTF"
-
strDocName = strDocName & ".rtf"
-
ActiveDocument.SaveAs FileName:=strDocName, FileFormat:=wdFormatRTF
-
Case Is = "HTML"
-
strDocName = strDocName & ".html"
-
ActiveDocument.SaveAs FileName:=strDocName, FileFormat:=wdFormatFilteredHTML
-
Case Is = "PDF"
-
strDocName = strDocName & ".pdf"
-
-
' *** Word 2007 users - remove the apostrophe at the start of the next line ***
-
'ActiveDocument.ExportAsFixedFormat OutputFileName:=strDocName, ExportFormat:=wdExportFormatPDF
-
-
End Select
-
d.Close
-
ChangeFileOpenDirectory oFolder
-
Next oFile
-
Application.ScreenUpdating = True
-
End Sub
-
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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.
|
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...
|
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?
...
|
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...
|
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()...
|
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();
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
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...
| |