ActiveDocument.ExportAsFixedFormat
(1)
SaveAsAOCELetter
(1)
WdFormatFilteredHTML
(1)
Microsoft Word
(1)
ActiveDocument.SaveAs
(1)
WdExportFormatPDF
(1)
Word.ApplicationClass
(1)
ActiveDocument.Close
(1)

How to open and save files in MS Word

Asked By Cal Who
18-Dec-09 08:41 PM
I submitted this to the Word.Programming NG but wonder if this can be done
as a VB program.

I know nothing about word macros but I have written Visual Basic programs so
maybe I be better off doing it in VB.

I did, years ago, write some code that used Word as a spell checker, but I
have no idea how to get Word to open and to save files.


I need to open each file (.doc) that is in a certain folder and
then save it both as a filtered HTML and also as a PDF.


I'd really appreciate a sample of something similar so I can get orientated
and know what to look up.



Thank in advance

My query us way too general.Using VB.Net I can get the file names.

Cal Who replied to Cal Who
18-Dec-09 09:51 PM
My query us way too general.
Using VB.Net I can get the file names.

If the following is OK I will be able to open the file
Private WordApp As New Word.ApplicationClass()

' WordApp.Activate();

WordApp.Visible = True

Dim aDoc As Word.Document = WordApp.Documents.Open(fileName, missing,
[readOnly], missing, missing, missing, missing, missing, missing, missing,
missing, isVisible)

aDoc.Activate()



Below is a Macro that I recored to save the file as an HTML and as a PDF.



I have no idea how to procede.

Do I convert the VBA code to VB.Net and simply run it?



What is, for example, Documents.Open FileName

and

ActiveDocument.ExportAsFixedFormat

Can I look this up someplace?



Thanks






Sub TEST1()
'
' TEST1 Macro
' TEST
'
ChangeFileOpenDirectory "C:\Documents and Settings\Cal\Desktop\junk\"
Documents.Open FileName:="Prayer.docx", ConfirmConversions:=False, _
ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto,
XMLTransform:=""
ChangeFileOpenDirectory _
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
7\Prayer.pdf" _
, ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False,
OptimizeFor:= _
wdExportOptimizeForOnScreen, Range:=wdExportAllDocument, From:=1,
To:=1, _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True,
_
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True,
_
BitmapMissingFonts:=True, UseISO19005_1:=False
ChangeFileOpenDirectory _
ActiveDocument.SaveAs FileName:="Prayer.htm", FileFormat:= _
wdFormatFilteredHTML, LockComments:=False, Password:="",
AddToRecentFiles _
EmbedTrueTypeFonts _
SaveAsAOCELetter:=False
ActiveWindow.View.Type = wdWebView
ActiveDocument.Close
RecentFiles(2).Open
ShowVisualBasicEditor = True
End Sub
Post Question To EggHeadCafe