How to open and save files in MS Word

  • Thread starter Thread starter Cal Who
  • Start date Start date
C

Cal Who

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.

If the following is OK I'll 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 _
"C:\Documents and Settings\Cal\Desktop\junk\St. Louis Gonzaga 7\"
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
"C:\Documents and Settings\Cal\Desktop\junk\St. Louis Gonzaga
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 _
"C:\Documents and Settings\Cal\Desktop\junk\St. Louis Gonzaga 9\"
ActiveDocument.SaveAs FileName:="Prayer.htm", FileFormat:= _
wdFormatFilteredHTML, LockComments:=False, Password:="",
AddToRecentFiles _
:=True, WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts _
:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
ActiveWindow.View.Type = wdWebView
ActiveDocument.Close
RecentFiles(2).Open
ShowVisualBasicEditor = True
End Sub
 
Back
Top