Forum Moderators: open
Please someone, tell me there's a better way (I know little about Office and zip/nada/nutting about VBA).
Thanks,
Ross
I know you can find the images via the shapes and inlineshapes properties of the document object as I've used this method to force inline images to embed themselves (sorry the source is at work, im not right now).
It's not the worlds nicest interface but at least you can watch what it does in the main word window to aid debugging, and as a plus its not as bad as crystal reports...
-Tony
Am I making this more convaluted than it need be?
Thanks all!
You can use the macro recorder to save as html, then just hit alt->F11 and view the code it made.
Thanks. With 1,400 of these puppies I'd like it to be a completely hands off exercise. I'm wondering if I can get the macro to run automatically as the docs get opened. That way I can open them programatically from VB using shell().
#!/usr/bin/perl -w
#
use strict;
#
use Win32::OLE;
#
my $w = '';
#
# trying to get a running instance of Word
eval {$w = Win32::OLE->GetActiveObject('Word.Application')};
die "Word not installed" if $@;
#
unless (defined $w) {
# open a new instance of Word
$w = Win32::OLE->new('Word.Application', sub {$_[0]->Quit;})
or die "Canīt start Word";
}
#
# open document
my $d = '';
my $file = 'k:\\word_document.doc';
eval {$d = $w->Documents->Open($file)};
die "Couldnīt open $file\n" if $@;
#
# get the content and print it
my $r = $d->Content;
print $r->Text;
Andreas
Sub Macro1()
'set Microsoft script Runtime under refrences
Dim FSO As Scripting.FileSystemObject
Dim SourceFolder As Scripting.Folder, SubFolder As Scripting.Folder
Dim FileItem As Scripting.File
Dim sFileName As String
Set FSO = New Scripting.FileSystemObject
Set SourceFolder = FSO.GetFolder("your folder with your word docs")
For Each FileItem In SourceFolder.Files
sFileName = FileItem.Name
SaveAsHTML sFileName, Left(sFileName, Len(sFileName) - 3) + ".htm"
Next FileItem
End Sub
'======your fuction =========
Function SaveAsHTML(sFile As String, sSaveAs As String)
'
Documents.Open FileName:=sFile, ConfirmConversions:=False, _
ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto
ActiveDocument.SaveAs FileName:=sSaveAs, FileFormat:=wdFormatHTML _
, LockComments:=False, Password:="", AddToRecentFiles:=True, _
WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False
End Function