CaptainSensible
Programmer
Hello!
This piece of code was succesfully used in many occasions to automatically convert word documents to html, but I'm now having a problem; the only difference between succesful cases is that the original file that is opened is on the network, opened in read-only, but saved on my computer where I have all access, and that word version is word 2002. Word opens, and displays the "save as" menu; as the function call is from java, the word application returns an error of that kind: error : file is read-only. Can there be another function to call for Word 2002? Like save as webpage? or does this problem come because of the rights on the network? In that case, why can I manually "save as" without problems having the same rights?
Thanks in advance if you can help!
Sorry for the comments, they are in french, but at least you speak VB!
Cyril.
Public Function doc2html(rFile As String, wFile As String) As Integer
doc2html = 0
On Error GoTo errorHandler
Set WordApp = New Word.Application
Set wordDocObj = WordApp.Documents.Open(rFile, , True)
With wordDocObj
' désactive toutes les alertes pouvant être générées par Word.
Application.DisplayAlerts = wdAlertsNone
WordApp.DisplayAlerts = wdAlertsNone
' accepte toutes le révisions qui on pu être faites au paravant.
.AcceptAllRevisions
' en désactivant les révisions, nous pouvons faire
' des modifications dans le document sans quelles soient visibles.
.TrackRevisions = False
' supprime tous les bas de page.
Dim section As Word.section
Dim footer As Word.HeaderFooter
For Each section In .Sections
For Each footer In section.Footers
footer.Range.Text = ""
Next
Next
' accepte toutes le révisions qui on pu être faites au paravant.
.AcceptAllRevisions
' sauvegarde le fichier au format HTML.
.SaveAs wFile, wdFormatHTML
'.Save
'Fermeture du fichier
.Close
End With
WordApp.Quit
Set wordDocObj = Nothing
Set WordApp = Nothing
Exit Function
This piece of code was succesfully used in many occasions to automatically convert word documents to html, but I'm now having a problem; the only difference between succesful cases is that the original file that is opened is on the network, opened in read-only, but saved on my computer where I have all access, and that word version is word 2002. Word opens, and displays the "save as" menu; as the function call is from java, the word application returns an error of that kind: error : file is read-only. Can there be another function to call for Word 2002? Like save as webpage? or does this problem come because of the rights on the network? In that case, why can I manually "save as" without problems having the same rights?
Thanks in advance if you can help!
Sorry for the comments, they are in french, but at least you speak VB!
Cyril.
Public Function doc2html(rFile As String, wFile As String) As Integer
doc2html = 0
On Error GoTo errorHandler
Set WordApp = New Word.Application
Set wordDocObj = WordApp.Documents.Open(rFile, , True)
With wordDocObj
' désactive toutes les alertes pouvant être générées par Word.
Application.DisplayAlerts = wdAlertsNone
WordApp.DisplayAlerts = wdAlertsNone
' accepte toutes le révisions qui on pu être faites au paravant.
.AcceptAllRevisions
' en désactivant les révisions, nous pouvons faire
' des modifications dans le document sans quelles soient visibles.
.TrackRevisions = False
' supprime tous les bas de page.
Dim section As Word.section
Dim footer As Word.HeaderFooter
For Each section In .Sections
For Each footer In section.Footers
footer.Range.Text = ""
Next
Next
' accepte toutes le révisions qui on pu être faites au paravant.
.AcceptAllRevisions
' sauvegarde le fichier au format HTML.
.SaveAs wFile, wdFormatHTML
'.Save
'Fermeture du fichier
.Close
End With
WordApp.Quit
Set wordDocObj = Nothing
Set WordApp = Nothing
Exit Function